Skip to content

Commit

Permalink
Fix issue with MimeKit disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Mar 6, 2024
1 parent b042828 commit b0c96b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public MimeKitEmailSender(ILogger<MimeKitEmailSender> logger,
{
_logger = logger;
_mailserverConfiguration = mailserverOptions.Value!;

}


Expand All @@ -25,7 +24,8 @@ public async Task SendEmailAsync(string to, string from, string subject, string
_logger.LogWarning("Sending email to {to} from {from} with subject {subject} using {type}.", to, from, subject, this.ToString());

using var client = new SmtpClient();
client.Connect(_mailserverConfiguration.Hostname, _mailserverConfiguration.Port, false);
client.Connect(_mailserverConfiguration.Hostname,
_mailserverConfiguration.Port, false);
var message = new MimeMessage();
message.From.Add(new MailboxAddress(from, from));
message.To.Add(new MailboxAddress(to, to));
Expand All @@ -34,6 +34,7 @@ public async Task SendEmailAsync(string to, string from, string subject, string

await client.SendAsync(message);

client.Disconnect(true);
await client.DisconnectAsync(true,
new CancellationToken(canceled: true));
}
}
2 changes: 1 addition & 1 deletion src/Clean.Architecture.Web/api.http
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ Content-Type: application/json
###

// Delete a contributor
@id_to_delete=4
@id_to_delete=1
DELETE {{host}}:{{port}}/Contributors/{{id_to_delete}}

0 comments on commit b0c96b2

Please sign in to comment.