I'm on this bug since fews days and maybe someone can give some some clues about this issue :
MailKit.Net.Smtp.SmtpStream.ReadAheadAsync(Boolean doAsync, CancellationToken cancellationToken) at MailKit.Net.Smtp.SmtpStream.ReadResponseAsync(Boolean doAsync, CancellationToken cancellationToken) at MailKit.Net.Smtp.SmtpClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, Boolean doAsync, CancellationToken cancellationToken) at SafetyStudio.Services.Courriels.EmailService.Send(EmailMessage emailMessage) in C:\Users\Louis\Source\Repos\SafetyStudio\SafetyStudio\Services\Courriels\EmailService.cs:line 58 | The SMTP server has unexpectedly disconnected. ! MailKit
//Be careful that the SmtpClient class is the one from Mailkit not the framework!
using (var emailClient = new SmtpClient())
{
try
{
//The last parameter here is to use SSL (Which you should!)
await emailClient.ConnectAsync(_emailConfiguration.SmtpServer, _emailConfiguration.SmtpPort, MailKit.Security.SecureSocketOptions.None);
//Remove any OAuth functionality as we won't be using it.
emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
await emailClient.AuthenticateAsync(_emailConfiguration.SmtpUsername, _emailConfiguration.SmtpPassword);
await emailClient.SendAsync(message);
await emailClient.DisconnectAsync(true);
emailClient.Dispose();
}
catch (Exception ex)
{
this.logger.LogError($"Erreur dans l'envoi d'un courriel {ex}");
return ex;
}
return null;
}
I try with port 25 and same error. 587 for TSL. I have a valid certificate.
"EmailConfiguration": {
"SmtpServer": "servername",
"SmtpPort": 587,
"SmtpUsername": "aaaaaaaaaaa",
"SmtpPassword": "ssssssssss!",
"PopServer": "popserver",
"PopPort": 995,
"PopUsername": "popusername",
"PopPassword": "poppassword"