How can I send an activation email when new users register in my website using asp.net c#? I have tried the steps described this link but I have faced this error:
System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
Is there any solution to this or any other way to send an email?
this is my code
using (MailMessage mm = new MailMessage("[email protected]", txtEmail.Text))
{
mm.Subject = "Account Activation";
string body = "Hello " + txtUsername.Text.Trim() + ",";
body += "<br /><br />Please click the following link to activate your account";
body += "<br /><a href = '" + Request.Url.AbsoluteUri.Replace("CS.aspx", "CS_Activation.aspx?ActivationCode=" + activationCode) + "'>Click here to activate your account.</a>";
body += "<br /><br />Thanks";
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("[email protected]", "<password>");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
The proposed duplicate did not solve the problem. I am already using port 587.
net_io_connectionclosed, it sounds like that's NOT happening.smtp.gmail.com, SUGGESTIONS: 1) Contact your e-mail administrator. Make sure your settings are correct; review his e-mail logs for errors. 2) Try Google e-mail: emailarchitect.net/easendmail/kb/csharp.aspx?cat=2smtp.UseDefaultCredentials = true;should besmtp.UseDefaultCredentials = false;- because you just gave it non-default credentials