From 4865db181642dda88d9671c83fb3aee8fa23eb90 Mon Sep 17 00:00:00 2001 From: Slendy Date: Mon, 2 Jan 2023 05:03:41 -0600 Subject: [PATCH] Create SmtpClient per email instead of reusing --- ProjectLighthouse/Helpers/SMTPHelper.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse/Helpers/SMTPHelper.cs b/ProjectLighthouse/Helpers/SMTPHelper.cs index defd9db4..92ce601d 100644 --- a/ProjectLighthouse/Helpers/SMTPHelper.cs +++ b/ProjectLighthouse/Helpers/SMTPHelper.cs @@ -14,7 +14,6 @@ public class SMTPHelper internal static readonly SMTPHelper Instance = new(); - private readonly SmtpClient client; private readonly MailAddress fromAddress; private readonly ConcurrentQueue emailQueue = new(); @@ -29,11 +28,6 @@ public class SMTPHelper { if (!ServerConfiguration.Instance.Mail.MailEnabled) return; - this.client = new SmtpClient(ServerConfiguration.Instance.Mail.Host, ServerConfiguration.Instance.Mail.Port) - { - EnableSsl = ServerConfiguration.Instance.Mail.UseSSL, - Credentials = new NetworkCredential(ServerConfiguration.Instance.Mail.Username, ServerConfiguration.Instance.Mail.Password), - }; this.fromAddress = new MailAddress(ServerConfiguration.Instance.Mail.FromAddress, ServerConfiguration.Instance.Mail.FromName); this.stopSignal = false; @@ -49,7 +43,12 @@ public class SMTPHelper try { - this.client.Send(entry.Message); + using SmtpClient client = new() + { + EnableSsl = ServerConfiguration.Instance.Mail.UseSSL, + Credentials = new NetworkCredential(ServerConfiguration.Instance.Mail.Username, ServerConfiguration.Instance.Mail.Password), + }; + await client.SendMailAsync(entry.Message); entry.Result.SetResult(true); } catch (Exception e)