当我尝试发送电子邮件至包含突出字符(E)的地址SmtpClient.Send()方法抛出此异常:
System.Net.Mail.SmtpException:客户端或服务器配置为仅用于电子邮件地址与ASCII本地部分:lé[email protected]。 在System.Net.Mail.MailAddress.GetAddress(布尔allowUnicode) 在System.Net.Mail.SmtpClient.ValidateUnicodeRequirement(... MAILMESSAGE) 在System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE)
消息的配方使我的事情有可能是我可以激活,使这项工作,虽然我还没有发现关于这个问题的任何设置。
我尝试了好几种SMTP服务器,包括Gmail。这里有一个摄制的相关位:
码
var msg = new MailMessage();
msg.Subject = "Test";
msg.From = new MailAddress("[email protected]");
msg.To.Add(new MailAddress("lé[email protected]"));
new SmtpClient().Send(msg);
的app.config
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.gmail.com" port="587" userName="[email protected]" password="password" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
如果您SmtpClient实例的DeliveryFormat属性设置为SmtpDeliveryFormat.SevenBit
(默认值),那么你需要确保发送EHLO当.NET,同时它试图以发送电子邮件的SMTP网关与SMTPUTF8回复。 SmtpClient使用此摸出如果网关能够支持UTF8。
如果DeliveryFormat是SmtpDeliveryFormat.International
,那么你就可以无论发送。
迟到的回答,但是,我解决了这个指定这样的编码:
var mailMessage = new MailMessage
{
From = new MailAddress("[email protected]", "Test User", Encoding.UTF8)
}
在我的情况下,服务器造成此错误。