【发布时间】:2013-12-29 08:00:51
【问题描述】:
我正在设置一个发送邮件的功能(作为订单确认,但那是以后的事情)。
问题是邮件是从公司的交换服务器发送的,到目前为止我得到的只是连接失败。
我正在与服务器技术人员沟通,试图找出问题所在,而且自从我设置电子邮件(在 cms 端)以来已经有一段时间了,我可能犯了一个愚蠢的错误,所以也许这里有人会抓住它:)
web.config:(服务器技术指定的端口号)
(为了安全起见,所有信息都替换为通用但一致的名称)
<system.net>
<mailSettings>
<smtp from="info@mydomain.com">
<network host="smtp.ourexchangeserver.dk" userName="info@mydomain.com" password="secret" port="26" />
</smtp>
</mailSettings>
剃须刀脚本测试:
@{
try {
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("myadress@gmail.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("info@mydomain.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Send(message);
}
catch(Exception ex)
{
<p> error: <br/> @ex.ToString() </p>
}
}
异常中捕获的错误:
System.Net.Mail.SmtpException: Failure sending mail. --->
System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
提前谢谢你。
【问题讨论】:
标签: asp.net email razor smtp umbraco