【发布时间】:2011-05-23 09:18:57
【问题描述】:
我需要向电子邮件地址中包含国际字符的收件人发送电子邮件。一个示例电子邮件是:
GaÙl@asterixthe.com
我已经进行了很多搜索,但我找到的信息是针对正文而不是收件人的。我是否需要以某种方式对此进行 mime 编码,如果需要,如何?
我得到的代码如下:
MailMessage mailMessage =
new MailMessage(email.SenderEmailAddress, email.RecipientEmailAddress, "Why hello there!", emailMessage)
{
IsBodyHtml = true,
BodyEncoding = new System.Text.UTF8Encoding()
};
SmtpClient smtpClient = new SmtpClient("localhost")
{
Port = 25,
};
smtpClient.Send(mailMessage);
谢谢,
西蒙
编辑:这是例外情况
System.FormatException: The specified string is not in the form required for an
e-mail address.
at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset,
String& displayName)
at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset)
at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
at System.Net.Mail.MailAddressCollection.Add(String addresses)
at System.Net.Mail.Message..ctor(String from, String to)
at System.Net.Mail.MailMessage..ctor(String from, String to)
at System.Net.Mail.MailMessage..ctor(String from, String to, String subject,
String body)
【问题讨论】:
-
如果你这样发送邮件,而不用指定编码会怎样?
-
它会引发异常 - 我会更新问题。塔:)
-
我认为这是重复的:stackoverflow.com/questions/760150/… 也许这会对你有所帮助