如何使用c#从gmail阅读电子邮件
我想创建窗口应用程序,通过它我可以从gmail读取电子邮件。
实际上我想阅读正确的电子邮件格式,例如,来自主题,cc和正文。
using (Imap imap = new Imap()) { imap.ConnectSSL("mail.company.com"); imap.Login("angel_y@company.com", "xyx***"); imap.SelectInbox(); List uids = imap.SearchFlag(Flag.Unseen); foreach (long uid in uids) { string eml = imap.GetMessageByUID(uid); IMail message = new MailBuilder() .CreateFromEml(eml); Console.WriteLine(message.Subject); Console.WriteLine(message.TextDataString); } imap.Close(true); }
这是错误。 无法建立连接,因为目标计算机主动拒绝它
试试这个我已经添加了端口号和gmail imap服务器以连接到服务器
using (Imap imap = new Imap()) { imap.ConnectSSL("imap.gmail.com", 993); imap.Login("angel_y@company.com", "xyx***"); // MailID As Username and Password imap.SelectInbox(); List uids = imap.SearchFlag(Flag.Unseen); foreach (long uid in uids) { string eml = imap.GetMessageByUID(uid); IMail message = new MailBuilder() .CreateFromEml(eml); Console.WriteLine(message.Subject); Console.WriteLine(message.TextDataString); } imap.Close(true); }
我相信有很多图书馆可以做到这一点。 快速搜索转向了这个:
http://code.msdn.microsoft.com/CSharpGmail
这是一个小工具/小部件应用程序,它有一些代码可以执行此操作: http : //www.codeproject.com/KB/gadgets/GadgetInterop.aspx
您可能需要确保使用正确的主机名和端口号。 配置这些设置取决于您用于.Net的IMAP API
但您要使用的设置列在Google的网站上。
- IMAP => imap.google.com:993(SSL)
- SMTP => smtp.google.com:587(TLS)
gmail通过其配置页面提供访问权限,以通过POP3 / IMAP下载电子邮件。 以下是我在Google上发现的一些可用于IMAP访问的链接。
http://www.codeproject.com/KB/IP/imaplibrary.aspx
在C#中访问Imap
http://koolwired.com/solutions/solutions.aspx?id=30
希望这有帮助!