在 C # 中访问 Imap

是否有一个内置的方法来访问一个 Imap 服务器(使用 SSL)在 C # 或有一个好的免费库?

161708 次浏览

我自己还没有尝试过,但是这是一个可以尝试的免费库(我对这个库的 SSL 部分不是很确定) :

http://www.codeproject.com/KB/IP/imaplibrary.aspx

另外,还有 xemail,它有 SSL 的参数:

Http://xemail-net.sourceforge.net/

[编辑]如果你(或客户)有钱买一个专业的邮件客户端,这个帖子有一些很好的建议:

建议.NET 组件访问电子邮件收件箱

IMAP 没有.NET 框架支持。 您需要使用一些第三方组件。

Try https://www.limilabs.com/mail, 它价格实惠,使用方便,还支持 SSL:

using(Imap imap = new Imap())
{
imap.ConnectSSL("imap.company.com");
imap.Login("user", "password");


imap.SelectInbox();
List<long> 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);
}

请注意,这是我创建的一个商业产品。

你可以在这里下载: https://www.limilabs.com/mail

MailSystem.NET 包含了你对 IMAP4的所有需求,它是免费和开源的。

(我参与了这个项目)

我一直在寻找 IMAP 解决方案有一段时间了,在尝试了相当多的解决方案之后,我决定使用 AE.Net 邮件

您可以通过转到 Code 选项卡并单击小的“下载”图标来下载代码。由于作者没有提供任何预先构建的下载,您必须自己编译它。(我相信你可以通过 NuGet 得到它)。不再有。在 bin/文件夹中的 dll。

这里没有文档,我认为这是一个缺点,但是我通过查看源代码(为开放源代码欢呼吧!)得以迅速完成这个工作并且使用智能感知。下面的代码专门连接到 Gmail 的 IMAP 服务器:

// 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页面以获得最新版本和一些更好的代码示例。

尝试使用图书馆: Https://imapx.codeplex.com/

这个图书馆是免费的,开源的,并且有这样的例子: Https://imapx.codeplex.com/wikipage?title=sample%20code%20for%20get%20messages%20from%20your%20inbox

希望对某些人有用,你可能想看看我的去 在它:

S22.Imap

虽然有一对夫妇好的和良好的记录 IMAP 库为.NET 它们都不是个人免费的,更不用说商业用途了 我只是不太满意大部分被抛弃的免费选择 I found.

IMAP 支持 IMAP IDLE 通知以及 SSL 和部分消息 我已经在制作 文件和保持 它是最新的,因为在我发现的项目中,文档往往很少 或者根本不存在。

随时给它一个尝试,让我知道,如果你遇到任何问题!