以下代码是我连接到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
答案 0 :(得分:0)
您的IMAP服务器管理员似乎已决定允许LOGIN
命令,但认为使用该身份验证方法登录时实际上不安全,无法允许您实际打开文件夹。
通常,MailKit尝试使用SASL身份验证(如果可用),但是您的IMAP服务器似乎并未宣传对任何SASL身份验证机制的支持。
在这些情况下,我通常建议尝试连接到SSL端口,或者至少尝试使用STARTTLS(您的服务器支持):
client.Connect (host, port, SecureSocketOptions.StartTls);
但是,您说即使使用SSL后此错误仍然存在,这意味着除了遵循错误消息中的建议并发送电子邮件至kefu@188.com寻求帮助之外,我没有其他建议。