提问人:Steve Schlichter 提问时间:6/27/2023 最后编辑:Steve Schlichter 更新时间:6/28/2023 访问量:161
.NET 6 SMTP 5.7.57 客户端未经过身份验证,无法从以下位置发送匿名邮件
.NET 6 SMTP 5.7.57 Client was not authenticated to send anonymous mail from
问:
我正在尝试通过System.Net.Mail发送邮件
var to = new MailAddress(notification.SendTo);
var from = new MailAddress(_smtpSettings.SMTPSendFrom);
var message = new MailMessage(from, to)
{
Subject = notification.Subject
,
Body = notification.Message
,
IsBodyHtml = true
};
var client = new SmtpClient()
{
Host = _smtpSettings.SMTPServer,
Port = _smtpSettings.SMTPPort,
EnableSsl = _smtpSettings.SMTPUseSSL,
UseDefaultCredentials = false,
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
};
if (_smtpSettings.SMTPDomain == string.Empty)
{
client.Credentials = new NetworkCredential(_smtpSettings.SMTPLogin, _smtpSettings.SMTPPassword);
}
else
{
client.Credentials = new NetworkCredential(_smtpSettings.SMTPLogin, _smtpSettings.SMTPPassword, _smtpSettings.SMTPDomain);
}
client.Send(message);
我收到的错误是 5.7.57 客户端未经过身份验证以发送匿名邮件。我已经参数化了我能想到的所有设置。已尝试发送域 UseDefaultCredentials true / false。
我还有我使用的 powershell 脚本,并且可以使用同一台计算机的相同帐户通过脚本发送邮件(在通过应用程序池 ID 登录应用程序时以我身份登录)。
一些添加的信息:邮件服务器是 Exchange 服务器。我发送的计算机是 Azure 托管的 Web 服务器。
有点难住了。
答:
0赞
dunxz
6/28/2023
#1
无法从托管的 Azure AppService 发送电子邮件(这是描述“Azure 托管 Web 服务器”时的意思吗?这被策略阻止,无法更改。您需要将 API 用于第三方(即 SendGrid 或其他)。我会尝试挖掘出相关的 MS 文章
评论
0赞
dunxz
6/28/2023
虽然表达方式不同,但我认为这个问题是 stackoverflow.com/questions/68484805/ 的重复......
0赞
dunxz
6/28/2023
实际上,这里还有更多建议:stackoverflow.com/questions/17666161/sending-email-from-azure
0赞
Steve Schlichter
6/28/2023
powershell 脚本在同一台计算机上运行,并且能够发送邮件。
评论
_smtpSettings.SMTPSendFrom
_smtpSettings