C# 向具有国际字符的收件人发送电子邮件
我需要向电子邮件地址中包含国际字符的收件人发送电子邮件。电子邮件示例如下: 嘎Ùl@asterixthe.com 我已经做了很多搜索,但我找到的信息是针对尸体的,而不是收件人的。我需要以某种方式对其进行mime编码吗?如果需要,如何编码 我得到的代码如下:C# 向具有国际字符的收件人发送电子邮件,c#,email,encoding,C#,Email,Encoding,我需要向电子邮件地址中包含国际字符的收件人发送电子邮件。电子邮件示例如下: 嘎Ùl@asterixthe.com 我已经做了很多搜索,但我找到的信息是针对尸体的,而不是收件人的。我需要以某种方式对其进行mime编码吗?如果需要,如何编码 我得到的代码如下: MailMessage mailMessage = new MailMessage(email.SenderEmailAddress, email.RecipientEmailAddress, "Why hello there!"
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)
嗯
在阅读.Net framework中MailMessage类的文档时,我发现该类的一个构造函数接收一个MailAddress对象
根据MSDN(http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx),DisplayName属性可以包含非ASCII字符,我认为如果它们显式指定,是因为名称不能包含它们
您是否尝试过另一个线程上的建议,其中一个线程说您可以使用“punycode”?如果您像这样发送邮件,而不麻烦指定编码,会发生什么情况?它会引发异常-我将更新问题。Ta:)我想这是重复的:也许这会对你有帮助。我试过使用MailMessage,但没有成功。我想知道这是否是这个特定应用程序必须使用.NET2的一个限制。至于微不足道的代码,我会再看一遍。谢谢。我接受了这个答案,尽管我仍然坚持它。我认为第三方组件可以做到这一点,但.NET2却不行,我很高兴将其作为标准草案。