SMTPClient.Send 无法解析特殊字符
我们正在使用 SmtpClient.Send 发送邮件。但不幸的是,具有一些特殊字符(如“æ”、“ø”和“å”(以及许多此类字符)的邮件正文无法正确发送,并且在收到时这些字符被损坏。
任何帮助将不胜感激。
问候, 稻田
We are using SmtpClient.Send to send mail. But unfortunately the mail body which is having some special character like "æ", "ø" and "å" (and many such) are not getting send properly and on reciept those character is getting corrupted.
Any help will be appreciated.
Regards,
Paddy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SmtpClient.Send 使用的默认编码是 us-ascii。您需要使用接收 MailMessage 的 覆盖 并设置邮件的 < href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.bodyencoding.aspx" rel="nofollow">BodyEncoding 属性包含您需要的特殊字符的编码。您可以对 SubjectEncoding 属性,对主题中的特殊字符进行编码。
您可以使用 Unicode 编码,但文档警告您消息的 TransferEncoding 将转换为 Base64。几乎所有电子邮件客户端都可以处理此问题,因此我认为这不会成为问题。
The default encoding used by SmtpClient.Send is us-ascii. You need to use the override that receives a MailMessage and set the message's BodyEncoding property to an encoding that contains the special characters you need. You can do the same for the SubjectEncoding property, to encode special characters in the Subject.
You can use a Unicode encoding but the documentation warns that your message's TransferEncoding will be converted to Base64. Almost all email clients can handle this, so I don't thing this will be an issue.