gpt4 book ai didi

c# - SmtpException : The client or server is only configured for e-mail addresses with ASCII local-parts 错误

转载 作者:可可西里 更新时间:2023-11-01 08:10:09 27 4
gpt4 key购买 nike

SmtpClient.Send()当我尝试将电子邮件发送到包含重音字符 (é) 的地址时,方法抛出此异常:

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)

消息的表述让我想到可能有一个我可以激活的设置来完成这项工作,尽管我还没有找到关于这个主题的任何内容。

我试过几个 SMTP 服务器,包括 Gmail。以下是复制的相关位:

代码

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>

最佳答案

如果DeliveryFormat SmtpClient 实例的属性设置为 SmtpDeliveryFormat.SevenBit (默认设置)然后您需要确保您的 SMTP 网关在尝试发送电子邮件时在 .NET 发送 EHLO 时使用 SMTPUTF8 进行回复。 SmtpClient 使用它来计算网关是否能够支持 UTF8。

根据 .NET Framework 4.5+ 和 .NET core 的源代码,接收服务器必须支持 UTF8,并且 DeliveryFormat 必须设置为 SmtpDeliveryFormat.International为了能够发送。

有关最新逻辑和完整详细信息,请参阅 IsUnicodeSupported:

关于c# - SmtpException : The client or server is only configured for e-mail addresses with ASCII local-parts 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13260772/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com