"The IMAP server has unexpectedly disconnected" 使用 993 端口和 MailKit

"The IMAP server has unexpectedly disconnected" using 993 port and MailKit

我最近将我的代码移到了 MailKit 库中,因为我使用的是 S22.Imap,但我发现维护不是很好。

我之前是通过143和993连接到自己的mailserver的,但是通过993和MailKit就没办法了

它只是说 "The IMAP server has unexpectedly disconnected"。它甚至没有到达 Authenticate 方法,并且日志唯一地显示 "Connected to imap://mail.xxx.com:993/".

我目前正在使用

imap.Connect(hostname, 993, SecureSocketOptions.None);

我什至尝试过不同的 SecureSocketOptions,但没有成功。知道什么可能是错的吗?如果我通过 143 连接并且在我使用 S22.Imap.

时它通过 993 工作正常

P.S: 它抛出的异常是 MailKit.Net.Imap.ImapProtocolException.

谢谢。

端口 993 是一个 SSL-wrapped 端口,因此您需要使用:

imap.Connect(hostname, 993, SecureSocketOptions.SslOnConnect);

对于端口 143,您可能想要使用:

imap.Connect(hostname, 143, SecureSocketOptions.StartTlsWhenAvailable);

我得到它来处理这个:

this._imap = new ImapClient();
this._imap.Connect(configuration.GetSection("MailSettings")["ImapServer"], 993, true);
this._imap.AuthenticationMechanisms.Remove("XOAUTH2");
this._imap.Authenticate(["ImapUser"], ["ImapPassword"]);