【问题标题】:Email not working on ASP.net电子邮件在 ASP.net 上不起作用
【发布时间】:2016-01-01 06:21:27
【问题描述】:

我是新的 ASP.Net,正在尝试解决邮件问题。我的网站托管在 Godaddy 服务器上,并在 ASP.Net 中开发。尝试使用以下脚本发送邮件,但抛出错误为 “发送邮件失败”

MailMessage mail = new MailMessage("firstmail@mail.com", "sfirstmail@mail.com");
    SmtpClient client = new SmtpClient();
    client.Host = "myhosting.secureserver.net";

    // Tried "relay-hosting.secureserver.net" -Errors-Unable to connect
    // Tried "smtpout.secureserver.net" -Errors-Unable to read data from
    // the transport connection: net_io_connectionclosed

    client.Port = 3535;  //Tried 80, 3535, 25, 465 (SSL)
    client.UseDefaultCredentials = false;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.EnableSsl = false;
    client.ServicePoint.MaxIdleTime = 1;
    client.Timeout = 10000;
    client.Credentials = new NetworkCredential("myloginid@mail.com", "mypassword");
    mail.IsBodyHtml = true;
    mail.Subject = "New Job";

    mail.IsBodyHtml = true;
    try
    {

        client.Send(mail);
        mail.Dispose();
        Response.Redirect("thankyou.html");
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);

    }

当 Print 异常在 ex 中得到以下内容:

System.Net.Mail.SmtpException:发送邮件失败。 ---> System.IO.IOException:无法从传输中读取数据 连接:net_io_connectionclosed。在 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(字节 [] 缓冲区, Int32 偏移,Int32 读取,布尔读取线)在 System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader 调用者,布尔 oneLine)在 System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader 调用者)在 System.Net.Mail.CheckCommand.Send(SmtpConnection conn, 字符串和响应)在 System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] 命令, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(邮件地址发件人, MailAddressCollection 收件人,字符串 deliveryNotify,布尔值 allowUnicode、SmtpFailedRecipientException& 异常)在 System.Net.Mail.SmtpClient.Send(MailMessage message) --- 内部结束 异常堆栈跟踪 --- 在 System.Net.Mail.SmtpClient.Send(MailMessage 消息)在 _Default.SendEmail(Object sender, EventArgs e)

【问题讨论】:

  • 查看异常消息,似乎端口、EnableSsl 或主机 smtp 服务器的设置不正确。请联系您的提供商以获取正确的设置。

标签: asp.net smtpclient


【解决方案1】:

如果你想使用465等端口你应该设置client.EnableSsl = true

此配置适合我:

    MailMessage message = new MailMessage
    {
      IsBodyHtml = true,
      Body = "text",
      Subject = "subject",
      To = { "firstmail@mail.com", "sfirstmail@mail.com" }
   };

   message.From = new MailAddress("sender@email.com");

   SmtpClient client = new SmtpClient("myhosting.secureserver.net", 465)
   {
      Credentials = new NetworkCredential("myloginid@mail.com", "mypassword"),
      EnableSsl = true
   };

   client.Send();

【讨论】:

    猜你喜欢
    • 2015-07-14
    • 2014-07-05
    • 1970-01-01
    • 2012-08-08
    • 2013-08-05
    • 2017-06-20
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    相关资源
    最近更新 更多