![](/img/trans.png)
[英]The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. C# WFM
[英]c# The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required
我正在嘗試使用以下 function 使用 C# 發送 email:
public static void SendEmail(string fromAddress, string password)
{
SmtpClient email = new SmtpClient
{
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
EnableSsl = true,
Host = "smtp.gmail.com",
Port = 587,
Credentials = new NetworkCredential(fromAddress, password)
};
string subject = "Mail subject";
string body = "Body";
try
{
Console.WriteLine("Sending email...");
email.Send(fromAddress, GetToAddress(), subject, body);
} catch (SmtpException e)
{
Console.WriteLine(e.Message);
}
}
我看到,為了使其正常工作,我需要在我的 gmail 帳戶上啟用安全性較低的應用程序。 但是,根據谷歌的說法,“為了幫助確保您的帳戶安全,從 2022 年 5 月 30 日起,谷歌不再支持使用要求您僅使用用戶名和密碼登錄 Google 帳戶的第三方應用程序或設備。” . 還有其他發送郵件的方法嗎?
您可以在 google 帳戶上啟用雙因素身份驗證,然后創建一個應用程序密碼
這將生成 16 個字符的“App 密碼”。 然后使用您之前使用的完全相同的代碼,並將標准用戶 Gmail 密碼替換為應用程序密碼。
前任:
SendEmail("Nave@gmail.com", "iodwsurnuyjfsxdc") // here iodwsurnuyjfsxdc means app password and Nave@gmail.com means app pass generated account email
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.