Email sending code working on localhost but not on server

与世无争的帅哥 提交于 2021-02-10 13:37:35

问题


I have written an email sending code using c#. I used GoDaddy's server for my website. It is working on localhost (VS 2013), But when deployed the same code on the server it gives the following error:


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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: A connection attempt fail because the connected party did not properly respond after a period of time, or establish connection fail because connected host has failed to respond [2607:f8b0:400e:c05::6c]:25

Stack Trace:

[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

Version Information: Microsoft .NET Framework version:4.0.30319; ASP.NET version:4.0.30319.34280


Code is given below:

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);

回答1:


I found the solution. Someone recommended me the Article. https://pk.godaddy.com/help/see-your-smtp-relays-3552. And I used the following code:

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);

Note: It was not working with port 25.




回答2:


Please Refer this url and follow the instruction very careflly.

http://manylinks.me/mypage.aspx?Page_Id=dbi92Xm

Note: Read all the 3 Steps.



来源:https://stackoverflow.com/questions/36945560/email-sending-code-working-on-localhost-but-not-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!