System.Net.Mail.SmtpException:不允許使用郵箱名稱.


使用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 truewhen 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屬性,則郵件將匿名發送到服務器。

 

官方文檔:https://docs.microsoft.com/zh-cn/dotnet/api/system.net.mail.smtpclient.usedefaultcredentials?view=netframework-4.7.1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM