我一直在尝试使用以下链接中提供的解决方案:
using c# .net librarires to check for IMAP messages from gmail servers
但我一直在犯这个错误:
连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机无法响应而建立连接失败
我在这里缺少什么东西。我的代码:
public List<MailMessage> ReadMail()
{
List<MailMessage> msgs;
using (var ic = new AE.Net.Mail.ImapClient("imap.gmail.com", "username@gmail.com", "pass-to-gmail", ImapClient.AuthMethods.Login, 993, true))
{
ic.SelectMailbox("INBOX");
msgs = new List<MailMessage>(ic.GetMessageCount());
msgs = ic.GetMessages(0, 100, false, true).ToList();
ic.Disconnect();
}
return msgs;
}
答案 0 :(得分:0)
使用这段代码连接到gmail。
ImapX.ImapClient client = null;
client = new ImapX.ImapClient("imap.gmail.com", 993, true);
if (!client.Connection())
{
MessageBox.Show("Couldn't connect to gmail. Check your internet connection and try again");
client = null;
return false;
}
if (!client.LogIn(email, password))
{
MessageBox.Show("Email And/Or password incorrect");
client = null;
return false;
}