I have windows dedicated server hosting more than 20 websites all built using asp.net. All my sites were sending emails using Gmail SMTP perfectly, but 2 days ago I asked tech-support to enable TLS1.2 and disable TLS1.0; when this happened all the emails stopped!
I have tried all solutions Here but still no use! Finally, I tried to use another email provider instead of Gmail and the emails are sent successfully.
Does anybody know what happens to Gmail services with TLS1.2?
Here is code sample:
public static bool SendMail(MailAddressCollection TO_List, string Subject, string Body, bool Is_Html_Body, System.Collections.Hashtable Attachments)
{
MailMessage msg = new MailMessage();
msg.Subject = Subject;
msg.Body = Body;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = Is_Html_Body;
msg.Priority = MailPriority.High;
SmtpClient sc = new SmtpClient();
if (Attachments != null)
{
foreach (Attachment AttachmentObj in Attachments.Values)
{
msg.Attachments.Add(AttachmentObj);
}
}
foreach (MailAddress To_Address in TO_List)
{
msg.To.Add(To_Address);
}
sc.Send(msg);
return true;
}
And this is web.config data:
<smtp from="myemail@gmail.com">
<network defaultCredentials="false" host="smtp.gmail.com" password="Pass here" userName="myemail@gmail.com" enableSsl="true" port="587" />
</smtp>