我正在使用Razor通过SMTP发送电子邮件。我正在使用相同的代码在不同的站点上执行此操作,但是我在这一个上遇到了错误。我更改了Web.config SMTP设置。我不确定我可能会做错什么。电子邮件问题“发送邮件失败”
@helper SendContactEmail(ContactFormModel formModel)
{
MailMessage mm = new MailMessage("[email protected]", "[email protected]");
mm.Subject = "New mail from J&M Services Contact Form";
//mm.Body = string.Format("Name: {0}\nEmail: {1}\n\nMessage: {2}", formModel.Name, formModel.Email, formModel.Comment);
mm.Body = "testing body";
mm.IsBodyHtml = false;
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(mm);
}
catch (Exception ex)
{
<h2>@ex.Message</h2>
<p>@ex.StackTrace</p>
}
}
我得到的错误是 “发送邮件失败” 和堆栈跟踪是 “在System.Net.Mail.SmtpClient.Send(消息MAILMESSAGE)在 ASP._Page_macroScripts_Contact_cshtml.b__16(的TextWriter __razor_helper_writer)in c:\ Dev \ SVN \ Main \ UmbracoApps \ umbJMServices \ umbJMServices \ macroScripts \ Contact.cshtml:line 262“。
262行是client.Send(mm);
我正在一个的InnerException:
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.SmtpConnection.GetConnection(的ServicePoint 的ServicePoint)在 System.Net.Mail.SmtpTransport.GetConnection(的ServicePoint的ServicePoint) 在System.Net.Mail。 SmtpClient.GetConnection()at System.Net.Mail.SmtpClient.Send(MailMessage message)
这通常意味着您的SMTP服务器存在问题。是否有InnerException? – SLaks
你有没有在你的web.config中定义的SMTP服务器? –
我加了我的InnerException到问题。 @SLaks – Eric