my website uses gmail smtp to send out emails. Nothing has been changed recently and all of a sudden it has stopped today. No code or password has been changed. This seems to be a common issue and many people suggest the same solution, unfortunately those didn't work for me today.
My SMTP code
using (var mail = new MailMessage())
{
const string smtp = "smtp.gmail.com";
const int port = 587;
var loginInfo = new NetworkCredential(account, password);
mail.From = new MailAddress(account);
mail.To.Add(new MailAddress(toAddress));
mail.Subject = subject;
mail.Body = message.ToString();
mail.IsBodyHtml = true;
try
{
using (var smtpClient = new SmtpClient(smtp, port))
{
smtpClient.EnableSsl = KnownKeys.EnableSSL;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = loginInfo;
smtpClient.Send(mail);
}
}
finally
{
//dispose the client
mail.Dispose();
}
}
What I've tried
The problem is that you are running the application behind a firewall e.g Sophos so its blocking outbound communication from the application
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With