我正在使用Razor通过SMTP发送电子邮件。我使用相同的代码在不同的站点中执行此操作,但我在此处收到错误。我已经更改了Web.config SMTP设置。我不确定我可能做错了什么。
@helper SendContactEmail(ContactFormModel formModel)
{
MailMessage mm = new MailMessage("contact@chasecomputerservices.com", "eric@chasecomputerservices.com");
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>
}
}
我得到的错误是“发送邮件失败”而StackTrace是 “在System.Net.Mail.SmtpClient.Send(MailMessage消息)处 ASP._Page_macroScripts_Contact_cshtml.b__16(的TextWriter __razor_helper_writer)在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(Byte []缓冲区, Int32 offset,Int32 read,Boolean readLine)at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller,Boolean oneLine)at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader 调用者)在System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) 在System.Net.Mail.SmtpClient.GetConnection()处 System.Net.Mail.SmtpClient.Send(MailMessage消息)
答案 0 :(得分:2)
我在公司内遇到此问题,因为防火墙拒绝了邮件。检查系统管理员是否有防火墙。