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