简体   繁体   English

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

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

I am using MailKit for sending and receiving emails.我正在使用MailKit发送和接收电子邮件。 but when I try to get emails, I get the Authentication Failed error.但是当我尝试接收电子邮件时,我收到Authentication Failed错误。 here is my code:这是我的代码:

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

Does anyone have any idea?有人有什么主意吗?

I know this sounds obvious, but the odds are that you're providing the wrong username and/or password.我知道这听起来很明显,但很可能是您提供了错误的用户名和/或密码。 That's what the error is saying.这就是错误所说的。

You can verify this by looking at the log file:您可以通过查看日志文件来验证这一点:

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

Maybe you can try creating a new Yahoo?也许你可以尝试创建一个新的雅虎? Mail account that fails to authenticate just like your real account and give me the username/password for that new account so that I can debug the issue?邮件帐户无法像您的真实帐户一样进行身份验证,并向我提供该新帐户的用户名/密码,以便我可以调试问题?

Does your username or password contain non-ASCII characters?您的用户名或密码是否包含非 ASCII 字符? How about punctuation characters?标点符号呢?

If you want me to dig into this, I need to know what the username/password are and what MailKit is sending in case it's sending the wrong strings (pretty sure it's not, but I'll look into it anyway).如果你想让我深入研究这个,我需要知道用户名/密码是什么,以及 MailKit 发送什么,以防它发送错误的字符串(很确定它不是,但无论如何我会调查它)。 If you don't give me that info, I can't diagnose the issue.如果你不给我这些信息,我就无法诊断这个问题。

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

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