【发布时间】:2017-05-13 06:19:20
【问题描述】:
我在 aspnet 核心上使用 MimeKit,一切都在本地运行,但是当我尝试在 azure App Service 上发送电子邮件时,我得到 “身份验证失败”。
我必须启用“允许安全性较低的应用程序”才能让它在本地工作。
这是我正在使用的代码:
using (var client = new SmtpClient())
{
await client.ConnectAsync("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
await client.AuthenticateAsync(_emailOptions.Username, _emailOptions.Password);
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
}
我已通过将 _emailOptions.Username 和 _emailOptions.Password 记录在抛出的异常中来验证它们是正确的
catch (Exception ex)
{
_log.LogError(new EventId(1), ex, "Username: '{0}', Password: '{1}'", _emailOptions.Username, _emailOptions.Password);
throw;
}
您对如何解决此问题有任何想法吗?
【问题讨论】:
-
我想知道您是否在 azure 和本地应用程序上使用 same 用户名和密码。
-
是的,我尝试硬编码用户名/密码。它可以在本地工作,但不能在 azure 中工作。
标签: azure asp.net-core azure-web-app-service mimekit