C# 将Mail.dll与Microsoft Exchange Imap版本4配合使用
我用它来阅读电子邮件。早些时候,我在读gmail账户的邮件,一切都正常。现在我需要将应用程序移动到另一台服务器并从microsoft exchange读取邮件。下面是我正在使用的代码C# 将Mail.dll与Microsoft Exchange Imap版本4配合使用,c#,.net,exchange-server,C#,.net,Exchange Server,我用它来阅读电子邮件。早些时候,我在读gmail账户的邮件,一切都正常。现在我需要将应用程序移动到另一台服务器并从microsoft exchange读取邮件。下面是我正在使用的代码 using (Imap imap = new Imap()) { imap.Connect("server-name", port number); imap.Login("username", "password"); imap.SelectInbox(); List<long>
using (Imap imap = new Imap())
{
imap.Connect("server-name", port number);
imap.Login("username", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.Seen);
if (uids.Count > 0)
{
string eml = imap.GetMessageByUID(uids[0]);
IMail email = new MailBuilder().CreateFromEml(eml);
imap.GetMessageByUID(uids[0]);
lbResponse.Text = email.Subject;
}
else
{
lbResponse.Text = "No mails found";
}
imap.Close();
}
使用(Imap Imap=new Imap())
{
imap.Connect(“服务器名称”,端口号);
imap.Login(“用户名”、“密码”);
imap.SelectInbox();
List uids=imap.Search(Flag.Seen);
如果(uids.Count>0)
{
字符串eml=imap.GetMessageByUID(uids[0]);
IMail email=new MailBuilder().CreateFromEml(eml);
imap.GetMessageByUID(uids[0]);
lbResponse.Text=email.Subject;
}
其他的
{
lbResponse.Text=“未找到邮件”;
}
imap.Close();
}
我已经使用telnet验证了端口和服务器,它是正确的。但是我得到了“无法从传输连接读取数据。连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机没有响应”错误。请提供帮助。确保在Exchange服务器上启用了IMAP:
也可考虑使用:
imap.Search(Flag.Seen)
SearchFlag在最新版本中已过时:请确保在Exchange服务器上启用了IMAP:
也可考虑使用:
imap.Search(Flag.Seen)
SearchFlag在最新版本中已过时:您使用的端口是什么?哪一行出现异常?您使用的是哪个端口?哪一行出现异常?