當我刪除註釋「//stmp.timeout」時,會發生超時錯誤。我應該怎麼做才能解決這個問題?發送電子郵件時出現異常「無法連接到遠程服務器」
這裏是我的代碼:
public ActionResult Index(EmailModel model)
{
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 180;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("[email protected] ","somepassword");
//smtp.Timeout = 20000;
}
try
{
smtp.Send("[email protected]",model.To, model.Subject, model.Message);
return View("Index");
}
catch (Exception ex)
{
Console.WriteLine(ex); //Should print stacktrace + details of inner exception
if (ex.InnerException != null)
{
Console.WriteLine("InnerException is: {0}", ex.InnerException);
}
}
return View("Index");
您的NetWorkCredentials用戶有空間嗎? – Steve 2012-07-25 21:14:22
@Steve我應該怎麼做的人 – 2012-07-25 21:15:02
後端口到465它給了我例外操作已超時 – 2012-07-25 21:33:50