我最近将我的代码移到了MailKit库,因为我使用的是S22.Imap,但我看到维护不是很好。
我之前通过143和993与我自己的邮件服务器连接,但没有办法通过993和MailKit。
它只是说“IMAP服务器意外断开连接”。它甚至没有达到Authenticate方法,日志唯一地说“连接到imap://mail.xxx.com:993 /”。
我目前正在使用
imap.Connect(hostname, 993, SecureSocketOptions.None);
我甚至尝试过不同的SecureSocketOptions而没有运气。知道什么可能是错的吗?如果我通过143连接工作正常,当我使用S22.Imap时它通过993工作。
P.S:它抛出的例外是一个MailKit.Net.Imap.ImapProtocolException
。
谢谢。
端口993是一个SSL包装的端口,因此您需要使用:
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"]);