我正在尝试在按钮点击事件后发送电子邮件。当我从本地机器上测试时,一切运行顺畅,电子邮件发送出去,我收到弹出消息,通知我“呼叫已经解决”。但是从服务器端运行页面“挂起” - 屏幕变暗,这应该发生,直到电子邮件被发送,但它保持这样。电子邮件不会从服务器端发出....
这就是我所做的: 我的代码:
MailMessage Mail = new MailMessage();
Mail.Subject = "Call Resolved";
Mail.To.Add(useremail);
// Mail.To.Add(useremail);
Mail.From = new MailAddress("notifications@oep.co.za");
// 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=""spoc@bcx.co.za"" 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=""spoc@bcx.co.za"" class=""link"">spoc@bcx.co.za</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="Notifications@smart-office.co.za">
<network host="host" userName="notifications@oep.co.za" password="password" port="25" />
</smtp>
</mailSettings>
出于安全原因,我已删除了密码和主机...我们将非常感谢您的帮助!这适用于另一个网站,但不适用于这个......
答案 0 :(得分:0)
我曾经遇到过这个问题,我在发布之前将EnableSsl
SmtpClient
字段的值更改为false
并且它对我有效,如果您已经有错,则将其更改为{ {1}}
答案 1 :(得分:0)
检入Windows事件查看器以获取更多详细信息。如果它与环境有问题,它可能会记录信息。