mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-23 01:39:03 +00:00
Create SmtpClient per email instead of reusing
This commit is contained in:
parent
cf1769ca77
commit
4865db1816
1 changed files with 6 additions and 7 deletions
|
@ -14,7 +14,6 @@ public class SMTPHelper
|
||||||
|
|
||||||
internal static readonly SMTPHelper Instance = new();
|
internal static readonly SMTPHelper Instance = new();
|
||||||
|
|
||||||
private readonly SmtpClient client;
|
|
||||||
private readonly MailAddress fromAddress;
|
private readonly MailAddress fromAddress;
|
||||||
|
|
||||||
private readonly ConcurrentQueue<EmailEntry> emailQueue = new();
|
private readonly ConcurrentQueue<EmailEntry> emailQueue = new();
|
||||||
|
@ -29,11 +28,6 @@ public class SMTPHelper
|
||||||
{
|
{
|
||||||
if (!ServerConfiguration.Instance.Mail.MailEnabled) return;
|
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.fromAddress = new MailAddress(ServerConfiguration.Instance.Mail.FromAddress, ServerConfiguration.Instance.Mail.FromName);
|
||||||
|
|
||||||
this.stopSignal = false;
|
this.stopSignal = false;
|
||||||
|
@ -49,7 +43,12 @@ public class SMTPHelper
|
||||||
|
|
||||||
try
|
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);
|
entry.Result.SetResult(true);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue