向具有国际字符的收件人发送电子邮件
我需要向电子邮件地址中包含国际字符的收件人发送一封电子邮件。电子邮件示例如下:
GaÙ[电子邮件受保护]
我已经进行了大量搜索,但我找到的信息是针对身体的,而不是针对接收者的。我是否需要以某种方式对其进行哑剧编码?如果需要,如何进行?
我得到的代码如下:
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)
I need to send an email to a recipient with international characters in the email address. An example email would be:
I've done quite a bit of searching but the information I'm finding is for the body and not the recipient. Do I need to mime encode this in some way and if so, how?
The code I've got is below:
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);
Thanks,
Simon
Edit: Here's the exception
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,
阅读.Net框架中MailMessage类的文档,我发现该类的构造函数之一接收一个MailAddress对象。
根据 MSDN (http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx), DisplayName 属性可以包含非 ASCII 字符,我认为如果他们明确指定是因为名字不能拥有它们。
您是否尝试过另一条线索上的建议,即您可以使用“punycode”?
Ok,
Reading the documentation for the MailMessage class in the .Net framework, I found that one of the constructors of the class receives a MailAddress object.
According to MSDN (http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx), the DisplayName property can contain non-ASCII characters, I would think that if they specify that explicitly is because the Name cannot have them.
Have you tried the suggestion on the other thread, the one saying that you could use "punycode"?