[英]c# The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required
[英]The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required
我的網站使用 gmail smtp 發送電子郵件。 最近什么都沒有改變,今天突然停止了。 沒有更改代碼或密碼。 這似乎是一個常見問題,許多人提出了相同的解決方案,不幸的是,這些對我來說今天不起作用。
我的 SMTP 代碼
using (var mail = new MailMessage())
{
const string smtp = "smtp.gmail.com";
const int port = 587;
var loginInfo = new NetworkCredential(account, password);
mail.From = new MailAddress(account);
mail.To.Add(new MailAddress(toAddress));
mail.Subject = subject;
mail.Body = message.ToString();
mail.IsBodyHtml = true;
try
{
using (var smtpClient = new SmtpClient(smtp, port))
{
smtpClient.EnableSsl = KnownKeys.EnableSSL;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = loginInfo;
smtpClient.Send(mail);
}
}
finally
{
//dispose the client
mail.Dispose();
}
}
我試過的
問題是您在防火牆后運行應用程序,例如 Sophos,因此它阻止了來自應用程序的出站通信
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.