我在aspnet核心上使用MimeKit,一切都在本地工作,但我得到「身份驗證失敗」當我嘗試在Azure App Service上發送電子郵件時。MimeKit azure gmail - >身份驗證失敗
我必須啓用「允許安全性較低的應用程序」才能使其在本地工作。
這是我使用的代碼:
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和本地應用上使用**相同的用戶名和密碼。 –
是的,我試圖硬編碼的用戶名/密碼。它在本地工作,但不在天藍色。 – user568327