开发者

.NET mailer encoding problem

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("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.Prio开发者_如何学编程rity = 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?


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

EmailMessage.BodyEncoding = Encoding.Unicode
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜