lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
https://lukelowrey.com/dotnet-email-guide-2021/
MIT License
3.04k stars 438 forks source link

System.ObjectDisposedException when sending email using smtpclient #332

Closed wilkovanderveen closed 2 years ago

wilkovanderveen commented 2 years ago

I am getting a System.ObjectDisposedException when i try to send an e-mail in a .NET core 6.0 project:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Mail.SmtpClient'.
   at System.Net.Mail.SmtpClient.SendAsync(MailMessage message, Object userToken)
   at FluentEmail.Smtp.SendMailEx.SendMailExImplAsync(SmtpClient client, MailMessage message, CancellationToken token)

I have tried to inject the smtpclient transient, scoped and as a singleton but niether one of the options fixed this issue.

wilkovanderveen commented 2 years ago

Never mind. Was my own mistake. I had to inject a custom smtpsender because of an issue with the current version and I had to use a singleton for the other services.