我在我的网站上使用GMail(Google Apps)作为SMTP服务器来发送电子邮件。邮件发送得很好,直到今天,当我注意到编码似乎很不稳定时。
在雅虎,整个邮件显示为中文字符(邮件完全是英文)。在Hotmail中,邮件的主题是中文字符。
以下是我的电子邮件代码:
Dim SMTPMail = New SmtpClient("smtp.gmail.com", 587)
SMTPMail.EnableSsl = True
SMTPMail.UseDefaultCredentials = False
Dim MailAuthentication = New NetworkCredential("mailer@website.com", "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)
Yahoo显示的标题中的编码是:
Content-Type: text/html; charset=utf-16
Content-Transfer-Encoding: base64
知道为什么会这样吗?
答案 0 :(得分:1)
如果您的整个邮件是英文(US-ASCII),请删除此行:
EmailMessage.BodyEncoding = Encoding.Unicode