电子邮件发送代码在本地主机上工作但不在服务器上
Email sending code working on localhost but not on server
我用c#写了一个邮件发送代码。我的网站使用 GoDaddy 的服务器。它在本地主机(VS 2013)上工作,但是当在服务器上部署相同的代码时,它会出现以下错误:
Server Error in '/' Application.
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
[2607:f8b0:400e:c05::6c]:25
描述:在执行当前网络请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详情:System.Net.Sockets.SocketException:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机有无法响应 [2607:f8b0:400e:c05::6c]:25
堆栈跟踪:
[SocketException (0x274c): A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed t
SMS.Portal.SendSMS.btnSubmit_Click(Object sender, EventArgs e) in
d:\Paul\ProximityMarketer\smsproximitysource\source\Portal\SendSMS.aspx.cs:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9633514
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +103
System.Web.UI.WebControls.Button.System.Web...IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1724
版本信息:Microsoft .NET Framework version:4.0.30319; ASP.NET version:4.0.30319.34280
代码如下:
SmtpClient smtpclient = new SmtpClient();
smtpclient.Host = "smtp.gmail.com";
smtpclient.Port = 25;
smtpclient.Credentials = new NetworkCredential("xxxxx@gmail.com", "Password");
smtpclient.EnableSsl = true;
MailMessage objmsg = new MailMessage();
objmsg.From = new MailAddress("xxxxx@gmail.com");
objmsg.To.Add(email);
objmsg.Subject = "testing";
objmsg.Body = myString.ToString();
objmsg.IsBodyHtml = true;
smtpclient.Send(objmsg);
我找到了解决方案。有人向我推荐了这篇文章。 https://pk.godaddy.com/help/see-your-smtp-relays-3552。我使用了以下代码:
SmtpClient ss = new SmtpClient();
ss.Host = "smtpout.secureserver.net";
ss.Port = 80;
ss.Timeout = 10000;
ss.DeliveryMethod = SmtpDeliveryMethod.Network;
ss.UseDefaultCredentials = false;
ss.EnableSsl = false;
ss.Credentials = new NetworkCredential("abc@yourdomain.com", "password");
MailMessage mailMsg = new MailMessage("abc@yourdomain.com", email, "subject here", "my body");
mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
ss.Send(mailMsg);
注意:它不适用于端口 25。
我用c#写了一个邮件发送代码。我的网站使用 GoDaddy 的服务器。它在本地主机(VS 2013)上工作,但是当在服务器上部署相同的代码时,它会出现以下错误:
Server Error in '/' Application.
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 [2607:f8b0:400e:c05::6c]:25
描述:在执行当前网络请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详情:System.Net.Sockets.SocketException:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机有无法响应 [2607:f8b0:400e:c05::6c]:25
堆栈跟踪:
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed t SMS.Portal.SendSMS.btnSubmit_Click(Object sender, EventArgs e) in d:\Paul\ProximityMarketer\smsproximitysource\source\Portal\SendSMS.aspx.cs:30 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9633514 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103 System.Web.UI.WebControls.Button.System.Web...IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
版本信息:Microsoft .NET Framework version:4.0.30319; ASP.NET version:4.0.30319.34280
代码如下:
SmtpClient smtpclient = new SmtpClient();
smtpclient.Host = "smtp.gmail.com";
smtpclient.Port = 25;
smtpclient.Credentials = new NetworkCredential("xxxxx@gmail.com", "Password");
smtpclient.EnableSsl = true;
MailMessage objmsg = new MailMessage();
objmsg.From = new MailAddress("xxxxx@gmail.com");
objmsg.To.Add(email);
objmsg.Subject = "testing";
objmsg.Body = myString.ToString();
objmsg.IsBodyHtml = true;
smtpclient.Send(objmsg);
我找到了解决方案。有人向我推荐了这篇文章。 https://pk.godaddy.com/help/see-your-smtp-relays-3552。我使用了以下代码:
SmtpClient ss = new SmtpClient();
ss.Host = "smtpout.secureserver.net";
ss.Port = 80;
ss.Timeout = 10000;
ss.DeliveryMethod = SmtpDeliveryMethod.Network;
ss.UseDefaultCredentials = false;
ss.EnableSsl = false;
ss.Credentials = new NetworkCredential("abc@yourdomain.com", "password");
MailMessage mailMsg = new MailMessage("abc@yourdomain.com", email, "subject here", "my body");
mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
ss.Send(mailMsg);
注意:它不适用于端口 25。