0
我能夠從LocalHost成功發送電子郵件。 託管我的網站後,我無法發送。 以下是錯誤:無法使用asp.net&C#從遠程服務器發送電子郵件?
System.Net.Mail.SmtpException:SMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應是:5.7.0必須首先發出STARTTLS命令。 ha10sm40374374pbc.23 - gsmtp
任何人都可以幫助我解決這個問題。
下面是代碼:
public void SendMail(string ToMail, string subject, string Message)
{
// Gmail Address from where you send the mail
string fromAddress = "[email protected]";
// any address where the email will be sending
//string toAddress = ToMail;
//Password of your gmail address
const string fromPassword = "********";
// Passing the values and make a email formate to display
//string subject = subject;
string body = "\n\n"+Message;
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, ToMail, subject, body);
}
您能顯示您用來發送電子郵件的代碼嗎? –
請添加smtp.UseDefaultCredentials = true並檢查 –
即使在添加UseDefaultCredentials = true後也不起作用。 – user2667871