Email send not working with smtp configuration through c#

61 Views Asked by At

I am trying to send email through c# code with smtp configuration but am getting following error:

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

Or sometimes I get exception like:

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

My code is :

SmtpMail oMail = new SmtpMail("TryIt");
oMail.From = SenderEmail;
oMail.To = TxtEmail.Value;
oMail.Subject = "Password Reset";
string body = "Hello " + ",";
body += "<br /><br />Please click the following link to reset password";
body += "<br /><a href = '" + RedirectRegPage + "'>Click here</a>.";
body += "<br /><br />Thanks";
oMail.HtmlBody = body;
SmtpServer oServer = new SmtpServer("mail.ServerName.com");
oServer.User = //User EMail
oServer.Password = // User EmailPassword
oServer.Port = 465;
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
oSmtp.SendMail(oServer, oMail);
Session["Message"] = "MailSent";

The email is being sent successfully through my Outlook . Can anyone please guide what i am missing here so that i can conclude to some resolution.

0

There are 0 best solutions below