问题描述
SmtpClient.Send() 方法在以下情况下抛出此异常我尝试向包含重音字符 (é) 的地址发送电子邮件:
The SmtpClient.Send() method is throwing this exception when I try to send an email to an address containing an accentuated character (é):
System.Net.Mail.SmtpException:客户端或服务器仅配置对于带有 ASCII 本地部分的电子邮件地址:léo.xxx@example.com.
在 System.Net.Mail.MailAddress.GetAddress(布尔 allowUnicode)
在 System.Net.Mail.SmtpClient.ValidateUnicodeRequirement(MailMessage...)
在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)
System.Net.Mail.SmtpException: The client or server is only configured for e-mail addresses with ASCII local-parts: léo.xxx@example.com.
at System.Net.Mail.MailAddress.GetAddress(Boolean allowUnicode)
at System.Net.Mail.SmtpClient.ValidateUnicodeRequirement(MailMessage...)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
消息的表述让我觉得可能有一个设置可以激活来完成这项工作,尽管我还没有找到关于这个主题的任何内容.
The formulation of the message makes me thing there might be a setting that I can activate to make this work, though I haven't found anything on this subject.
我尝试了多个 SMTP 服务器,包括 Gmail.以下是再现的相关位:
I have tried several SMTP servers, including Gmail. Here are the relevant bits for a repro:
代码
var msg = new MailMessage();
msg.Subject = "Test";
msg.From = new MailAddress("xxx@gmail.com");
msg.To.Add(new MailAddress("léo.yyy@gmail.com"));
new SmtpClient().Send(msg);
app.config
<system.net>
<mailSettings>
<smtp from="xxx@gmail.com">
<network host="smtp.gmail.com" port="587" userName="xxx@gmail.com" password="password" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
推荐答案
如果SmtpClient 实例的 aspx" rel="nofollow noreferrer">DeliveryFormat 属性设置为 SmtpDeliveryFormat.SevenBit (默认)然后您需要确保您的 SMTP 网关正在回复 .NET 在尝试发送电子邮件时发送 .EHLO 时的 SMTPUTF8SmtpClient 使用它来确定网关是否能够支持 UTF8.
If the DeliveryFormat property of your SmtpClient instance is set to SmtpDeliveryFormat.SevenBit (the default) then you need to make sure your SMTP gateway is replying with SMTPUTF8 when sent EHLO by .NET while it's trying to send the email. SmtpClient uses this to work out if the gateway is able to support UTF8.
根据 .NET Framework 4.5+ 和 .NET core 的源,接收服务器必须支持 UTF8 并且 DeliveryFormat 必须设置为 SmtpDeliveryFormat.International为了能够发送.
According to the source for both .NET Framework 4.5+ and .NET core, the receiving server must support UTF8 and the DeliveryFormat must be set to SmtpDeliveryFormat.International in order to be able to send.
有关最新逻辑和完整详细信息,请参阅 IsUnicodeSupported in:
For the latest logic and full details, see IsUnicodeSupported in:
- 当前 .NET 源代码
- .NET Framework 参考源
这篇关于SmtpException:客户端或服务器仅配置为具有 ASCII 本地部分的电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)