I am getting this error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTL
This worked for me:
Set smtpclient.EnableSsl = true;
MailMessage mail = new MailMessage("FromEmail_Address", "ToEmail_Address");
SmtpClient smtpclient = new SmtpClient();
smtpclient.Port = 587;
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.UseDefaultCredentials = false;
smtpclient.Host = "smtp.gmail.com";
smtpclient.UseDefaultCredentials = false;
mail.Subject = "Email Subject";
mail.Body = "Content of the email";
smtpclient.EnableSsl = true;
smtpclient.Credentials = new System.Net.NetworkCredential()
{
UserName = "FromEmail_Address",
Password = "password of the email"
};
client.Send(mail);
Actually you can handle this in your web.config file by adding enableSsl="true". This worked for me and I didn't need to do anything in code.
e.g.
<network host="smtp.gmail.com" enableSsl="true" ... />
Try setting the EnableSsl property to true:
smtpClient.EnableSsl = true;
AFAIK this property can only be set in code and cannot be specified in the config file.