.NET 邮件程序编码问题
我在我的网站中使用 GMail (Google Apps) 作为 SMTP 服务器来发送电子邮件。邮件发送得很好,直到今天,我注意到编码似乎很不稳定。
在雅虎中,整个消息都显示为中文字符(邮件完全是英文的)。在Hotmail中,邮件的主题是汉字。
以下是我的电子邮件代码:
Dim SMTPMail = New SmtpClient("smtp.gmail.com", 587)
SMTPMail.EnableSsl = True
SMTPMail.UseDefaultCredentials = False
Dim MailAuthentication = New NetworkCredential("[email protected]", "blahblah")
SMTPMail.Credentials = MailAuthentication
Dim EmailMessage As New MailMessage(New MailAddress(FromAddress), New MailAddress(ToAddress))
EmailMessage.BodyEncoding = Encoding.Unicode
EmailMessage.Subject = "Blah blah"
EmailMessage.Body = "Blah blah"
EmailMessage.Priority = Priority
EmailMessage.IsBodyHtml = True
EmailMessage.From = New MailAddress(FromAddress)
SMTPMail.Send(EmailMessage)
雅虎显示的标头中的编码是:
Content-Type: text/html; charset=utf-16
Content-Transfer-Encoding: base64
知道为什么会发生这种情况吗?
I am using GMail (Google Apps) as an SMTP server in my website to send out emails. The mails were being sent out fine, until today, when I noticed that the encoding seemed to be wonky.
In Yahoo, the entire message is shown as Chinese characters (the mail is entirely in English). In Hotmail, the subject of the mail was in Chinese characters.
The below is my email code:
Dim SMTPMail = New SmtpClient("smtp.gmail.com", 587)
SMTPMail.EnableSsl = True
SMTPMail.UseDefaultCredentials = False
Dim MailAuthentication = New NetworkCredential("[email protected]", "blahblah")
SMTPMail.Credentials = MailAuthentication
Dim EmailMessage As New MailMessage(New MailAddress(FromAddress), New MailAddress(ToAddress))
EmailMessage.BodyEncoding = Encoding.Unicode
EmailMessage.Subject = "Blah blah"
EmailMessage.Body = "Blah blah"
EmailMessage.Priority = Priority
EmailMessage.IsBodyHtml = True
EmailMessage.From = New MailAddress(FromAddress)
SMTPMail.Send(EmailMessage)
The encoding in the header as shown by Yahoo are:
Content-Type: text/html; charset=utf-16
Content-Transfer-Encoding: base64
Any idea why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的整个消息都是英语 (US-ASCII),则删除此行:
If your entire message is in English (US-ASCII), then remove this line: