John Sheedy
John Sheedy
CC#
Created by John Sheedy on 2/29/2024 in #help
SmtpClient timing out
I am trying to use my C# program to send an email using my own mail server as well as Gmail. Whenever I try I keep getting a timeout and it doesn't matter if I change the timeout to 100 seconds or 1 second it still is timing out. Anything obvious with my code?
c#
var smtpClient = new SmtpClient()
{
Host = "smtp.gmail.com",
Timeout= 60000,
Port = 465,
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("[email protected]", "password")
};
var mailMessage = new MailMessage()
{
Subject = "Alarm Activated",
Body = message,
IsBodyHtml = true,
Priority = MailPriority.High,
From = new MailAddress("[email protected]", "Hein Alarms")
} ;
if (clsSettings.SafetySettings.emails.alert_Email1 != "") { mailMessage.To.Add(clsSettings.SafetySettings.emails.alert_Email1); }
if (clsSettings.SafetySettings.emails.alert_Email2 != "") { mailMessage.To.Add(clsSettings.SafetySettings.emails.alert_Email2); }
if (clsSettings.SafetySettings.emails.alert_Email3 != "") { mailMessage.To.Add(clsSettings.SafetySettings.emails.alert_Email3); }

try{smtpClient.Send(mailMessage);}
catch (Exception e){return;}
c#
var smtpClient = new SmtpClient()
{
Host = "smtp.gmail.com",
Timeout= 60000,
Port = 465,
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("[email protected]", "password")
};
var mailMessage = new MailMessage()
{
Subject = "Alarm Activated",
Body = message,
IsBodyHtml = true,
Priority = MailPriority.High,
From = new MailAddress("[email protected]", "Hein Alarms")
} ;
if (clsSettings.SafetySettings.emails.alert_Email1 != "") { mailMessage.To.Add(clsSettings.SafetySettings.emails.alert_Email1); }
if (clsSettings.SafetySettings.emails.alert_Email2 != "") { mailMessage.To.Add(clsSettings.SafetySettings.emails.alert_Email2); }
if (clsSettings.SafetySettings.emails.alert_Email3 != "") { mailMessage.To.Add(clsSettings.SafetySettings.emails.alert_Email3); }

try{smtpClient.Send(mailMessage);}
catch (Exception e){return;}
5 replies