访问中的imap C# [英] Accessing Imap in C#
问题描述
有没有在C#中访问IMAP服务器(使用SSL)内置法还是有一个很好的免费图书馆吗?
Is there a built-in method to access an Imap server (with SSL) in C# or is there a good free library?
推荐答案
我一直在寻找了一段时间的IMAP解决方案现在,并试图相当多之后,我与的AE.Net.Mail 。
I've been searching for an IMAP solution for a while now, and after trying quite a few, I'm going with AE.Net.Mail.
您可以通过转到code标签下载code和点击小下载图标。由于笔者不提供任何pre-内置的下载,您必须自己编译。 (我相信你能得到它通过的NuGet虽然)。不再有在bin /文件夹中的.dll。
You can download the code by going to the Code tab and click the small 'Download' icon. As the author does not provide any pre-built downloads, you must compile it yourself. (I believe you can get it through NuGet though). There is no longer a .dll in the bin/ folder.
有没有文件,这是我考虑的一个缺点,但我可以通过查看源$ C $ C(耶开源!),并使用智能感知掀起这件事。下面code专门连接到Gmail的IMAP服务器:
There is no documentation, which I consider a downside, but I was able to whip this up by looking at the source code (yay for open source!) and using Intellisense. The below code connects specifically to Gmail's IMAP server:
// Connect to the IMAP server. The 'true' parameter specifies to use SSL
// which is important (for Gmail at least)
ImapClient ic = new ImapClient("imap.gmail.com", "name@gmail.com", "pass",
ImapClient.AuthMethods.Login, 993, true);
// Select a mailbox. Case-insensitive
ic.SelectMailbox("INBOX");
Console.WriteLine(ic.GetMessageCount());
// Get the first *11* messages. 0 is the first message;
// and it also includes the 10th message, which is really the eleventh ;)
// MailMessage represents, well, a message in your mailbox
MailMessage[] mm = ic.GetMessages(0, 10);
foreach (MailMessage m in mm)
{
Console.WriteLine(m.Subject);
}
// Probably wiser to use a using statement
ic.Dispose();
请确保您检出 Github上页面的最新版本和一些更好的code的例子。
Make sure you checkout the Github page for the newest version and some better code examples.
这篇关于访问中的imap C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!