當我嘗試從C#發送電子郵件的SMTP例外
MailMessage mail = new MailMessage("[email protected]", "[email protected]");
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "pwd");
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
型「System.Net.Mail.SmtpException」未處理的異常發生在System.dll中 附加發送電子郵件我有這樣的錯誤信息:SMTP服務器需要安全連接或客戶端未通過身份驗證。 服務器響應是:5.5.1需要身份驗證。
檢查,如果您可以登錄到從應用程序上運行的計算機的Gmail帳戶。有時谷歌可以阻止遠程計算機訪問。還檢查是否啓用了2因素身份驗證。 – user1666620
檢查您的Gmail帳戶的安全設置,並啓用不太安全的應用程序 – Sybren
也許[這些](http://stackoverflow.com/questions/9801224/smtpclient-with-gmail)答案將幫助您 – voytek