2

I'm trying to send an email with the 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

Error message: 6.6.0 Error sending message for delivery.

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");
            }

        }
Simply Ged
  • 8,250
  • 11
  • 32
  • 40
Csibi Norbert
  • 780
  • 1
  • 11
  • 35
  • Not sure if this is your problem, but the using statement around an SmtpClient object and the async way to send mails are not good friends. You risk disposing the client before sending the mail. I would try to remove the using, just to see if this changes anything – Steve Dec 15 '19 at 19:44
  • @Steve still the same, i tried to take out the using statement, it still not working. Also, i took the await out, still not working. Although it was working before... – Csibi Norbert Dec 15 '19 at 19:52
  • From here: http://www.mimekit.net/docs/html/T_MailKit_Net_Smtp_SmtpErrorCode.htm "The message was not accepted for delivery. This may happen if the server runs out of available disk space. " , could this be it? :) – Dimitri Dec 15 '19 at 19:54
  • @Dimitri Strange, nope.. I made a new email address, and i`ve put the new one inside, now i`m getting another error: {"The SMTP server has unexpectedly disconnected."} :) – Csibi Norbert Dec 15 '19 at 20:04
  • Could it be you account to `yahoo.com` that is blocked? – Frank Nielsen Dec 15 '19 at 20:37
  • I just created a new account to test if this works, still doesn`t... And my account which i`m using here, is not blocked, just checked again. :/ – Csibi Norbert Dec 15 '19 at 20:50
  • Tried to connect with the right credentials ( that i have in the code) but on the browser it logs in, and in the code it doesn`t even authenticate – Csibi Norbert Dec 15 '19 at 20:52
  • The original error message you got suggests that the problem is that the server is not accepting the message for delivery. In other words, the problem is not with your code, the problem is server-side. – jstedfast Dec 15 '19 at 21:09
  • Try getting a [protocol log](https://github.com/jstedfast/MailKit/blob/master/FAQ.md#ProtocolLog) - it may be helpful. Be sure to scrub the `AUTH` command, though. – jstedfast Dec 15 '19 at 21:14
  • This looks like it may be helpful: https://support.mozilla.org/en-US/questions/1268916 – jstedfast Dec 15 '19 at 21:54
  • This problem is associated with Yahoo service and not your code. I recommend to use another service provider like Gmail(Google). – milad Oct 07 '21 at 15:15

1 Answers1

0

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. 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.

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. 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! 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.

jstedfast
  • 35,744
  • 5
  • 97
  • 110
  • I completely agree with your last paragraph! I think this problem is just associated with Yahoo policies. I strongly recommend the questioner to use other service providers like Gmail and so on. – milad Oct 07 '21 at 15:13