我在我的 C# 程序中使用ImapX 2来检查 Gmail 帐户中的电子邮件,但整个过程似乎花费了太多时间,我将在代码中解释:
public static string checkForSubject() {
ImapX.ImapClient client = new ImapX.ImapClient();
client.Port = 993;
client.UseSsl = true;
client.Host = "imap.gmail.com";
if (client.Connect()) {
client.Login(Constants.EMAIL_SENDER, Constants.EMAIL_SENDER_PASSWORD);
var messages = client.Folders.Inbox.Search("ALL"); // THIS LINE takes like 5-10 seconds to complete
foreach (var item in messages) {
if (item.Subject.StartsWith("HELLO_")) {
string s = item.Subject;
return s;
}
}
}
return null;
}
我的代码有问题,还是 IMAP 访问正常?