我正在尝试通过MailKit发送电子邮件。但是,它以前一直在工作,现在突然不再工作了。我可以连接并进行身份验证,但是当它到达发送电子邮件时,会引发错误。
错误代码:MessageNotAccepted
错误消息:6.6.0发送消息进行传递时出错。
这是我的代码
var message = new MimeMessage();
message.From.Add(new MailboxAddress(contactModel.Name, "[email protected]"));
// This needs to be put in a configuration file
message.To.Add(new MailboxAddress("NorbertDev", "[email protected]"));
message.Subject = $"{contactModel.Name} contacted me!";
message.Body = new TextPart("plain") {
Text = contactModel.Message +
" Details of sender: " + contactModel.EmailAddress + ", " + contactModel.ContactNumber + " ," + contactModel.Name
};
using (var client = new SmtpClient())
{
try
{
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls11 |
System.Security.Authentication.SslProtocols.Tls12 |
System.Security.Authentication.SslProtocols.Tls |
System.Security.Authentication.SslProtocols.Ssl3 |
System.Security.Authentication.SslProtocols.Ssl2;
if (!client.IsConnected)
{
await client.ConnectAsync("smtp.mail.yahoo.com", 587, false).ConfigureAwait(false);
}
if (!client.IsAuthenticated)
{
await client.AuthenticateAsync("[email protected]", "aaaaaaaaaaa").ConfigureAwait(false);
}
await client.SendAsync(message).ConfigureAwait(false); <-- Here is the error
await client.DisconnectAsync(true).ConfigureAwait(false);
return "success";
}
catch (Exception e)
{
throw new Exception($"The email from {contactModel.EmailAddress} captured but not sent to the owner");
}
}
尝试获取Protocol Log。它可能有助于诊断问题。
基于https://support.mozilla.org/en-US/questions/1268916,似乎Thunderbird上的某些用户遇到了相同的错误。也许值得一读的是,导致这些Thunderbird用户出现问题的原因是什么,也可以看看其中的任何一个也适用于您。
例如,To
标头中没有任何地址和/或将您自己添加到Bcc
列表中似乎引起了这种问题。我尚不清楚是否还有其他任何原因可以导致这种情况,但是事实是其他邮件客户端也遇到了来自Yahoo Mail的非常奇怪的错误消息!向我暗示这可能是Yahoo Mail!错误。
无论如何,您遇到的问题似乎与身份验证无关,它似乎只是Yahoo Mail的SMTP服务器在拒绝邮件时执行的一种积极的垃圾邮件过滤。