.NET 邮件程序编码问题

发布于 2024-10-31 11:02:50 字数 1043 浏览 4 评论 0原文

我在我的网站中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅我要高飞 2024-11-07 11:02:50

如果您的整个消息都是英语 (US-ASCII),则删除此行:

EmailMessage.BodyEncoding = Encoding.Unicode

If your entire message is in English (US-ASCII), then remove this line:

EmailMessage.BodyEncoding = Encoding.Unicode
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文