MailKit.Net.Imap.ImapProtocolException: "Syntax error in IMAP server greeting. Unexpected token: [atom: OK]"

MailKit.Net.Imap.ImapProtocolException: "Syntax error in IMAP server greeting. Unexpected token: [atom: OK]"

代码:

using (var client = new ImapClient(new ProtocolLogger("logImap.txt")))
{
    // For demo-purposes, accept all SSL certificates
    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
    client.Connect("imap.yandex.ru", 993, true);
    client.Authenticate(login, password);
    // The Inbox folder is always available on all IMAP servers...
    var inbox = client.Inbox;
    inbox.Open(FolderAccess.ReadOnly);
    Console.WriteLine("Total messages: {0}", inbox.Count);
    Console.WriteLine("Recent messages: {0}", inbox.Recent);
    for (int i = 0; i < inbox.Count; i++)
    {
        var message = inbox.GetMessage(i);
        Console.WriteLine("Subject: {0}", message.Subject);
    }
    client.Disconnect(true);
}

堆栈跟踪:

MailKit.Net.Imap.ImapEngine.AssertToken(MailKit.Net.Imap.ImapToken, MailKit.Net.Imap.ImapTokenType, string, object[]) MailKit.Net.Imap.ImapEngine.ConnectAsync(MailKit.Net.Imap.ImapStream, bool, System.Threading.CancellationToken) System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() MailKit.Net.Imap.ImapClient.ConnectAsync(string, int, MailKit.Security.SecureSocketOptions, bool, System.Threading.CancellationToken) System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) ...

和logImap.txt:

Connected to imaps://imap.yandex.ru:993/
S: OK IMAP4

这个问题我该怎么办?

这是我 运行 你的程序时得到的(在 Connect() 调用后注释掉所有内容,因为我没有要使用的用户名和密码字符串)。

Connected to imaps://imap.yandex.ru:993/
S: * OK Yandex IMAP4rev1 at iva1-ea72743daf57.qloud-c.yandex.net:993 ready to talk with ::ffff:72.94.35.232:51061, 2020-Mar-20 16:12:10, ACZCR35nKa61
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4rev1 CHILDREN UNSELECT LITERAL+ NAMESPACE XLIST BINARY UIDPLUS ENABLE ID AUTH=PLAIN AUTH=XOAUTH2 IDLE MOVE
S: A00000000 OK CAPABILITY Completed.
C: A00000001 LOGOUT
S: * BYE IMAP4rev1 Server logging out
S: A00000001 OK LOGOUT Completed.

在您的日志中,问候语看起来不同:

S: OK IMAP4

请注意,在我的例子中,问候语的第一个字符是 *

这表明您连接的服务器是损坏的 IMAP 服务器,而不是 MailKit 的错。

Yandex 似乎是 IMAP 服务器的轮询机制。我接的那个明明可以用,你接的那个坏了