Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task Notify(string subject, string message)
{
try
{
using var client = CreateSmtpClient();
using var client = await CreateSmtpClient();
var mailMessage = new MimeMessage();

var reportReceiver = appConfiguration.Value.ReportReceiver;
Expand All @@ -29,7 +29,11 @@ public async Task Notify(string subject, string message)
mailMessage.From.Add(MailboxAddress.Parse(appConfiguration.Value.Mail.From));
mailMessage.To.Add(MailboxAddress.Parse(reportReceiver));
mailMessage.Subject = subject;
mailMessage.Body = new TextPart("html") { Text = message };

var builder = new BodyBuilder ();
builder.HtmlBody = message.Replace("\n", "<br/>");

mailMessage.Body = builder.ToMessageBody();

await client.SendAsync(mailMessage);
await client.DisconnectAsync(true);
Expand All @@ -49,7 +53,7 @@ public async Task Notify(string subject, string message)
}
}

private SmtpClient CreateSmtpClient()
private async Task<SmtpClient> CreateSmtpClient()
{
var host = appConfiguration.Value.Mail.Host;
var port = appConfiguration.Value.Mail.Port;
Expand All @@ -62,8 +66,8 @@ private SmtpClient CreateSmtpClient()
ArgumentException.ThrowIfNullOrWhiteSpace(password, nameof(password));

var client = new SmtpClient();
client.Connect(host, port, enableSsl);
client.Authenticate(username, password);
await client.ConnectAsync(host, port, enableSsl);
await client.AuthenticateAsync(username, password);

return client;
}
Expand Down
Loading