几天以来我一直在这个错误上,也许有人可以提供一些关于这个问题的线索:
MailKit.Net.Smtp.SmtpStream.ReadResponseAsync(Boolean doAsync, CancellationToken cancelToken) 的 MailKit.Net.Smtp.SmtpClient.ConnectAsync(字符串主机,Int32 端口)的 MailKit.Net.Smtp.SmtpStream.ReadAheadAsync(布尔 doAsync,CancellationToken cancelToken) C:\Users\Louis\Source\Repos\SafetyStudio\SafetyStudio\Services\Courriels\EmailService.cs 中 SafetyStudio.Services.Courriels.EmailService.Send(EmailMessage emailMessage) 的 SecureSocketOptions 选项、布尔 doAsync、CancellationToken cancelToken):第 58 行 | SMTP 服务器意外断开。!邮件套件
//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;
}
我尝试使用端口 25 和相同的错误。587 用于 TSL。我有一个有效的证书。
"EmailConfiguration": {
"SmtpServer": "servername",
"SmtpPort": 587,
"SmtpUsername": "aaaaaaaaaaa",
"SmtpPassword": "ssssssssss!",
"PopServer": "popserver",
"PopPort": 995,
"PopUsername": "popusername",
"PopPassword": "poppassword"