【发布时间】:2018-04-01 03:28:14
【问题描述】:
我在通过 asp.net SMTP 服务器发送电子邮件时遇到错误。它说操作已超时。如何克服异常?
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.From = new MailAddress("mymailid@hotmail.com");
mail.To.Add("yourmailid@gmail.com");
mail.Subject = "Verify your account";
mail.Body = "Your OTP for your account verification is "+OTP.ToString()+". Enter your OTP in verification window.";
mail.IsBodyHtml = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Timeout = 20000;
SmtpServer.Send(mail);
errmsgShow.Text = "Mail sent";
}
catch (Exception e)
{
//string errMsg = "alert('OTP sending failed. Error: " +e.ToString()+ "')";
//ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", errMsg, true);
//Console.WriteLine(e.Message.ToString());
errmsgShow.Text = e.ToString();
}
我也在下面的web.config中包含了
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.live.com" port="25" userName="mymailid@hotmail.com" password="password" enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
【问题讨论】: