MailKit:从 Pop3Client 调用 Authenticate 方法时抛出 Authentication Failed class

MailKit: throws Authentication Failed while calling Authenticate method from the Pop3Client class

我正在使用 MailKit 发送和接收电子邮件。但是当我尝试接收电子邮件时,出现 Authentication Failed 错误。这是我的代码:

using MailKit.Net.Pop3;
using MimeKit;

public List<Email> GetEmails()
{
    using var emailClient = new Pop3Client();
    emailClient.Connect("pop.mail.yahoo.com", 995, true);
    emailClient.AuthenticationMechanisms.Remove("XOAUTH2"); //commenting this line won't help.
    emailClient.Authenticate("email", "password"); // this line throws 'Authentication Failed' exception.

    var emails = new List<Email>();
    for (int i = 0; i < 10; i++)
    {
        var message = emailClient.GetMessage(i);
        var emailMessage = new Email
        {
            Content = message.TextBody,
            Subject = message.Subject
        };
        emails.Add(emailMessage);
    }

    return emails;
}

有人知道吗?

我知道这听起来很明显,但很可能是您提供了错误的用户名 and/or 密码。这就是错误的意思。

您可以通过查看日志文件来验证这一点:

var emailClient = new Pop3Client(new ProtocolLogger("pop3.log"))

或许您可以尝试创建一个新的 Yahoo!无法像您的真实帐户一样进行身份验证的邮件帐户,请给我该新帐户的 username/password 以便我调试问题?

您的用户名或密码是否包含非 ASCII 字符?标点符号呢?

如果你想让我深入研究这个问题,我需要知道 username/password 是什么以及 MailKit 正在发送什么以防它发送错误的字符串(很确定不是,但我会调查无论如何)。如果您不提供该信息,我将无法诊断问题。