我想在按钮单击事件后发送电子邮件。当从我的本地机器进行测试时,一切运行顺利,电子邮件会发送出去,然后弹出消息通知我“呼叫已解决”。但从服务器端运行页面“挂起” - 屏幕变暗,这应该发生,直到电子邮件发送,但它仍然是这样。电子邮件没有得到从服务器端发送出去....电子邮件在本地工作,但不在服务器上
这是我做了什么: 我的代码:
MailMessage Mail = new MailMessage();
Mail.Subject = "Call Resolved";
Mail.To.Add(useremail);
// Mail.To.Add(useremail);
Mail.From = new MailAddress("[email protected]");
// string path = Server.MapPath(@"..\Images\SOSLetterhead.png");
// string path = PopulateEmailImage();
string path = Server.MapPath(@"\Images\ItsmBCXHeader.gif");
LinkedResource logo = new LinkedResource(path);
logo.ContentId = "header";
AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><head>" +
@"<meta content=""text/html; charset=utf-8"" http-equiv=""Content-Type""/> " +
@"<title></title></head><body ><style> " +
@".auto-style1 {width: 188px; }table tr td{ border:solid;border-width:1px;} .link{color:red;}</style> " +
@"<img alt="""" height=""130"" src=""cid:header"" width=""675"" /> " +
@"<div style=""color:red; font-weight:bold; text-align:left; border:none; margin-right:20%;"" > " +
@"<h3>This message is sent on behalf of <br /> The Business Connexion Global Service Management Centre</h3> " +
@"<h5><i>Please do not respond to the sender as this mailbox does not receive return mail. <br /> " +
@"Use the Link located at the bottom of the e-mail to Respond </i></h5> </div><br />" +
@"<div>Dear <b>" + CustName + "</b></div><br /> " +
@"<div>We are pleased to inform you that your reported Incident <b>" + incidentNo + "</b>, has been resolved. </div><br /> " +
@"<div><b>Incident Summary report as follows:</b></div> <br /> " +
@"<table style=""width:45%; border:solid; border-width:3px; background-color:#E2E2E2;""> " +
@"<tr><td class=""auto-style1""><b>Incident Number:</b></td><td>" + incidentNo + "</td> " +
@"<tr><td class=""auto-style1""><b>Status:</b></td><td>" + stats + "</td></tr> " +
@"<tr><td class=""auto-style1""><b>CI Serial No:</b></td><td>" + serialNo + "</td></tr> " +
@"<tr><td class=""auto-style1""><b>Incident Summary:</b></td><td>" + incidentSum + "</td></tr> " +
@"<tr><td class=""auto-style1""><b>Incident Notes:</b></td><td>" + incidentNotes + "</td></tr> " +
@"<tr><td class=""auto-style1""><b>Resolution:</b></td><td>" + resolution + "</td></tr> " +
@"</table><br /><div> " +
@"If you have any queries or if you would like to change your contact details, please contact the <br /> Global Service Management Centre. " +
@"</div><br /><div> " +
@"<a href=""[email protected]"" class=""link"">Click here if you would like to contact the Global Service Management Centre via e-mail</a> </div> " +
@"<br /><div><b>011 266 1102</b> (National, South African number) <br /><b>+27 (0) 266 1102</b> (International number)<br /> " +
@"E-mail queries to <a href=""[email protected]"" class=""link"">[email protected]</a> <br /></div><br /><div><b>Yours in service <br /> " +
@"Global Service Management Centre</b></div></body></html>", null, MediaTypeNames.Text.Html);
av1.LinkedResources.Add(logo);
Mail.AlternateViews.Add(av1);
System.Configuration.Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("~/web.config");
MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;
if (mailSettings != null)
{
int port = mailSettings.Smtp.Network.Port;
string host = mailSettings.Smtp.Network.Host;
string password = mailSettings.Smtp.Network.Password;
string username = mailSettings.Smtp.Network.UserName;
}
SmtpClient SMTP = new SmtpClient();
SMTP.Send(Mail);
而且我的web.config:
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network host="host" userName="[email protected]" password="password" port="25" />
</smtp>
</mailSettings>
我已删除密码和主机出于安全原因...任何帮助将不胜感激!这部作品在其他网站上,但不是在这一个.....
从您部署到的服务器,您可以telnet进入邮件服务器,检查它是否在预期的端口上侦听? – mwrichardson
@mwrichardson,是的,我可以通过telnet连接......一切看起来都OK ......谢谢你的回复! – Kerieks