简体   繁体   English

在发送电子邮件时,MailKit 在 C# 中引发错误

[英]On Send email, MailKit throws an error in C#

I'm trying to send an email with the MailKit.我正在尝试使用 MailKit 发送电子邮件。 However, it was working before and now suddenly is not working anymore.但是,它以前可以工作,现在突然不再工作了。 I'm able to connect & authenticate but when it reaches the send email, is throwing an error.我能够连接并进行身份验证,但是当它到达发送电子邮件时,会引发错误。

Error code: MessageNotAccepted错误代码:MessageNotAccepted

Error message: 6.6.0 Error sending message for delivery.错误消息:6.6.0 发送消息以进行交付时出错。

Here is my code这是我的代码

        var message = new MimeMessage();
        message.From.Add(new MailboxAddress(contactModel.Name, "ssssss@yahoo.com"));
        // This needs to be put in a configuration file
        message.To.Add(new MailboxAddress("NorbertDev", "sssssss@gmail.com"));
        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("ssssss@yahoo.com", "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");
            }

        }

Try getting a Protocol Log .尝试获取协议日志 It may help diagnose the problem.它可能有助于诊断问题。

Based on https://support.mozilla.org/en-US/questions/1268916 it seems that some users on Thunderbird have gotten the same error.基于https://support.mozilla.org/en-US/questions/1268916,Thunderbird上的一些用户似乎遇到了同样的错误。 It may be worth reading what sort of things caused the issue for those Thunderbird users to see if any of them apply to you as well.对于那些 Thunderbird 用户来说,什么样的事情导致了这个问题,看看它们是否也适用于你,这可能值得一读。

For example, not having any addresses in the To header and/or adding yourself to the Bcc list seems to cause this sort of issue.例如, To标题中没有任何地址和/或将自己添加到Bcc列表似乎会导致此类问题。 I'm not clear if there are any other things that can cause this, but the fact that other mail clients are also experiencing this very odd error message from Yahoo Mail!我不清楚是否还有其他原因会导致这种情况,但事实上其他邮件客户端也遇到了来自 Yahoo Mail! 的这个非常奇怪的错误消息! suggests to me that this may be a Yahoo Mail!向我建议这可能是雅虎邮件! bug.漏洞。

In any event, the problem you are hitting does not seem to be related to authentication, it seems to just be sort sort of aggressive spam filtering being done by Yahoo Mail's SMTP server in rejecting messages.无论如何,您遇到的问题似乎与身份验证无关,它似乎只是雅虎邮件的 SMTP 服务器在拒绝邮件时执行的某种激进的垃圾邮件过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM