C
C#10mo ago
John Sheedy

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;}
3 Replies
The Fog from Human Resources
Try port 587 maybe Afaik 465 is no longer used for SMTP
John Sheedy
John SheedyOP10mo ago
changing it worked but only after I created a legacy App Password. Thanks
The Fog from Human Resources
No problem!
Want results from more Discord servers?
Add your server