我正在设置一个发送邮件的功能(作为订单确认,但那是稍后的事情)。
问题是邮件是从公司的交换服务器发送的,到目前为止我得到的只是连接失败。
我正在与服务器技术人员沟通,试图找出问题所在,自从我设置电子邮件(在 cms 端)以来已经有一段时间了,我可能会犯一个愚蠢的错误,所以也许这里有人会发现它:)
web.config:(服务器技术指定的端口号)
(为了安全起见,所有信息均替换为通用但一致的名称)
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.ourexchangeserver.dk" userName="[email protected]" password="secret" port="26" />
</smtp>
</mailSettings>
razor脚本测试:
@{
try {
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("[email protected]");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("[email protected]");
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
提前谢谢您。
您能否确认他们为您提供的端口凭据是 Exchange 服务器的而不是 Exchange Web 服务托管 API。
其次,根据配置,使用 SMTP 服务器发送电子邮件时需要指定字段。例如
OMsg1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "smtp"; // ypur SMTP serner name
OMsg1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
并且明智地。
请找到下面的链接,在 C# 中使用 SMTP 发送电子邮件,您可以制作它的 RAZOR 副本。
http://forums.asp.net/t/1602115.aspx
希望有帮助。
谢谢
找到以下链接,它将帮助您从 UMBRACO 发送邮件。在剃刀宏中发送电子邮件
http://our.umbraco.org/forum/developers/razor/22536-Send-email-in-razor-macro