当我删除注释“//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");
+0
您的NetWorkCredentials用户有空间吗? –
2012-07-25 21:14:22
+0
@Steve我应该怎么做的人 –
2012-07-25 21:15:02
+0
后端口到465它给了我例外操作已超时 –
2012-07-25 21:33:50