C# Mailkit - 由于登录不安全,IMap 无法 Open/Examine 收件箱?

C# Mailkit - IMap Unable Open/Examine Inbox due to Unsafe Login?

以下代码是我如何连接到我的 IMap 服务器,这似乎可以毫无问题地连接到其他 IMap 服务器并通过身份验证,但由于登录不安全,它不允许我打开收件箱?

inbox.Open(FolderAccess.ReadOnly) 是代码中断并抛出以下错误的地方。

The IMAP server replied to the 'EXAMINE' command with a 'NO' response: EXAMINE Unsafe Login. Please contact kefu@188.com for help

我尝试启用 SSL,但结果还是一样。我可以使用其他电子邮件客户端(例如 Microsoft Mail)登录此电子邮件。

    public static int getResult(string ToEmail, string imapServer, int port, string user, string pwd, DateTime timeCodeRequested)
    {
        using (var client = new ImapClient(new ProtocolLogger("C:/log/log.txt")))
        {
            client.ServerCertificateValidationCallback = (s, c, h, e) => true;

            // Remove the XOAUTH2 authentication mechanism since we don't have an OAuth2 token.
            client.AuthenticationMechanisms.Remove("XOAUTH2");

            client.Connect(imapServer, port, true);

            client.Authenticate(user, pwd);

            TryAgain:
            // The Inbox folder is always available on all IMAP servers...
            var inbox = client.Inbox;
            inbox.Open(FolderAccess.ReadOnly);

            IList<OrderBy> orderBy = new[] { OrderBy.ReverseArrival };
            IList<UniqueId> ids = inbox.Sort(SearchQuery.FromContains("sh@n.com")
                .And(SearchQuery.ToContains(ToEmail))
                .And(SearchQuery.DeliveredAfter(timeCodeRequested)
                .And(SearchQuery.YoungerThan(80))), orderBy);

            if (ids.Count == 0)
            {
                goto TryAgain;
            }
            else
            {
                foreach (UniqueId id in ids)
                {
                    var message = inbox.GetMessage(id);
                    var ex = message.Subject.ToString();
                    ex = ex.Substring(ex.Count() - 6);

                    try
                    {
                        return Convert.ToInt32(ex);
                    }
                    catch
                    {
                        continue;
                    }
                }
                goto TryAgain;
            }
        }
    }

这是 IMap 日志的输出 C:/log/log.txt,我已经删除了 IMap 凭据

S: * OK Coremail System IMap Server C: A00000000 CAPABILITY S: * CAPABILITY IMAP4rev1 XLIST SPECIAL-USE ID LITERAL+ STARTTLS XAPPLEPUSHSERVICE UIDPLUS X-CM-EXT-1 S: A00000000 OK CAPABILITY completed C: A00000001 LOGIN email password S: A00000001 OK LOGIN completed C: A00000002 CAPABILITY S: * CAPABILITY IMAP4rev1 XLIST SPECIAL-USE ID LITERAL+ STARTTLS XAPPLEPUSHSERVICE UIDPLUS X-CM-EXT-1 S: A00000002 OK CAPABILITY completed C: A00000003 LIST "" "" S: * LIST (\Noselect) "/" "" S: A00000003 OK LIST Completed C: A00000004 LIST "" "INBOX" S: * LIST () "/" "INBOX" S: A00000004 OK LIST Completed C: A00000005 LIST (SPECIAL-USE) "" "*" S: * LIST (\Drafts) "/" "&g0l6P3ux-" S: * LIST (\Sent) "/" "&XfJT0ZAB-" S: * LIST (\Trash) "/" "&XfJSIJZk-" S: * LIST (\Junk) "/" "&V4NXPpCuTvY-" S: A00000005 OK LIST Completed C: A00000006 EXAMINE INBOX S: A00000006 NO EXAMINE Unsafe Login. Please contact kefu@188.com for help

您的 IMAP 服务器管理员似乎已决定允许 LOGIN 命令,但认为它太不安全,不允许您在使用该身份验证方法登录时实际打开文件夹。

通常情况下,MailKit 会尝试使用 SASL 身份验证(如果可用),但您的 IMAP 服务器似乎并未公布对任何 SASL 身份验证机制的支持。

在这些情况下,我通常建议尝试连接到 SSL 端口或至少尝试使用 STARTTLS(您的服务器支持):

client.Connect (host, port, SecureSocketOptions.StartTls);

但是,您说即使在使用 SSL 后此错误仍然存​​在,这意味着除了遵循错误消息中的建议并发送电子邮件至 kefu@188.com 寻求帮助外,我没有其他建议可以给您。