使用SmtpClient發送郵件的時候,出現了如題錯誤。
解決方案:
將 SmtpClient.UseDefaultCredentials 屬性設置為 true 。
官方文檔說明:
Some SMTP servers require that the client be authenticated before the server sends e-mail on its behalf. Set this property to true
when this SmtpClient object should, if requested by the server, authenticate using the default credentials of the currently logged on user. For client applications, this is the desired behavior in most scenarios.
Credentials information can also be specified using the application and machine configuration files. For more information, see <mailSettings> Element (Network Settings) .
If the UseDefaultCredentials property is set to false,
then the value set in the Credentials property will be used for the credentials when connecting to the server. If the UseDefaultCredentials property is set to false
and the Credentials property has not been set, then mail is sent to the server anonymously.
谷歌翻譯:
一些SMTP服務器要求客戶端在服務器代表它發送電子郵件之前進行認證。 如果此服務器請求,此SmtpClient對象應使用當前登錄用戶的默認憑據進行身份驗證,請將此屬性設置為true。 對於客戶端應用程序,這是大多數情況下所需的行為。
憑證信息也可以使用應用程序和機器配置文件來指定。 有關更多信息,請參閱<mailSettings>元素(網絡設置)。
如果UseDefaultCredentials屬性設置為false,則在連接到服務器時,Credentials屬性中設置的值將用於憑據。 如果UseDefaultCredentials屬性設置為false,並且尚未設置Credentials屬性,則郵件將匿名發送到服務器。