我是新的ASP.Net并尝试修复邮件问题。我的网站托管在godaddy服务器上,并在ASP.Net中开发。尝试使用下面的脚本,但它的投掷的错误为“发送邮件失败”电子邮件不能在ASP.net上工作
MailMessage mail = new MailMessage("[email protected]", "[email protected]");
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("[email protected]", "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);
}
当打印异常得到了下面的前发送邮件:
System.Net.Mail.SmtpException : 邮件发送失败。 ---> System.IO.IOException:无法从传输 连接读取数据:net_io_connectionclosed。在在 系统 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(字节[]缓冲液, 的Int32偏移的Int32读,布尔的readLine)在 System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader 呼叫者,布尔ONELINE)。 Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader 呼叫者)在System.Net.Mail.CheckCommand.Send(SmtpConnection康恩, 字符串&响应)在System.Net.Mail.MailCommand.Send(SmtpConnection 康恩,字节[]命令,MailAddress from,Boolean allowUnicode)at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients,String deliveryNotify,Boolean allowUnicode,SmtpF ailedRecipientException &除外)在 System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE)---内 异常堆栈跟踪的末尾在在 _Default System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE) .SendEmail(对象发件人,EventArgs的)
查看异常消息,看起来设置对端口,EnableSsl或主机smtp服务器都是不正确的。请联系您的提供商以获取正确的设置 –