Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everybody,

I have used the following code to send email using ASP.Net with C#. it worked perfectly. but now it is not working. it gives error message "Server does not support secure connection". and if I try to change smtp.EnableSsl = false; then it gives another error "The SMTP Server requires a secure connection or the client was not authenticated. The server response was:5.7.0 must issue a STARTTLS command first."
so, please solve my problem.

Thanks in advance.

What I have tried:

MailMessage mail = new MailMessage();
mail.To.Add("Yahoo Email ID");
mail.From = new MailAddress("Gmail Email ID");
mail.Subject = "Subject of mail";
mail.Body = "Body of Email";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential("My Gmail Email","Gmail Password");
mail.Priority = MailPriority.High;
smtp.Send(mail);
mail.Dispose();
mail = null;
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
Posted
Updated 27-Aug-16 2:24am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900