【问题标题】:Operation has timed out error on ASP.NETASP.NET 上的操作超时错误
【发布时间】: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>

【问题讨论】:

    标签: asp.net c#-4.0 smtp


    【解决方案1】:

    尝试删除SmtpServer.Timeout = 20000;。

    更新:

    我看到你有SmtpClient SmtpServer = new SmtpClient();。

    SmtpServer 是 SmtpMail SmtpMail.SmtpServer 的属性。尝试更改变量名称,例如

    SmtpClient mailClient = new SmtpClient();
    

    【讨论】:

    • 更改了 SmtpClient 对象名称。但错误仍然相同。
    猜你喜欢
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 1970-01-01
    相关资源
    最近更新 更多