在 C# 中访问 Imap
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/670183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Accessing Imap in C#
提问by UnkwnTech
Is there a built-in method to access an Imap server (with SSL) in C# or is there a good free library?
是否有内置方法可以在 C# 中访问 Imap 服务器(使用 SSL),或者是否有好的免费库?
回答by Espo
I haven't tried it myself, but this is a free library you could try (I not so sure about the SSL part on this one):
我自己没有尝试过,但这是一个您可以尝试的免费库(我不太确定这个库中的 SSL 部分):
http://www.codeproject.com/KB/IP/imaplibrary.aspx
http://www.codeproject.com/KB/IP/imaplibrary.aspx
Also, there is xemail, which has parameters for SSL:
此外,还有 xemail,它具有 SSL 参数:
http://xemail-net.sourceforge.net/
http://xemail-net.sourceforge.net/
[EDIT] If you (or the client) have the money for a professional mail-client, this thread has some good recommendations:
[编辑] 如果您(或客户)有钱购买专业的邮件客户端,该线程有一些很好的建议:
Recommendations for a .NET component to access an email inbox
回答by Pawel Lesnikowski
There is no .NET framework support for IMAP. You'll need to use some 3rd party component.
IMAP 没有 .NET 框架支持。您需要使用一些 3rd 方组件。
Try https://www.limilabs.com/mail, it's very affordable and easy to use, it also supports SSL:
试试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);
}
Please note that this is a commercial product I've created.
请注意,这是我创建的商业产品。
You can download it here: https://www.limilabs.com/mail.
你可以在这里下载:https: //www.limilabs.com/mail。
回答by Pawel Lesnikowski
MailSystem.NETcontains all your need for IMAP4. It's free & open source.
MailSystem.NET包含您对 IMAP4 的所有需求。它是免费和开源的。
(I'm involved in the project)
(我参与了这个项目)
回答by Dominic K
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.
我一直在寻找 IMAP 解决方案一段时间了,在尝试了很多之后,我打算使用AE.Net.Mail。
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.
您可以通过转到“代码”选项卡并单击“下载”小图标来下载代码。由于作者不提供任何预建下载,您必须自己编译。(我相信你可以通过 NuGet 获得它)。bin/ 文件夹中不再有 .dll。
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:
没有文档,我认为这是一个缺点,但我能够通过查看源代码(开源的耶!)并使用 Intellisense 来提升它。以下代码专门连接到 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", "[email protected]", "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();
Make sure you checkout the Githubpage for the newest version and some better code examples.
请务必查看Github页面以获取最新版本和一些更好的代码示例。
回答by a777andrey
Try use the library : https://imapx.codeplex.com/
尝试使用库:https: //imapx.codeplex.com/
That library free, open source and have example at this : https://imapx.codeplex.com/wikipage?title=Sample%20code%20for%20get%20messages%20from%20your%20inbox
该库免费,开源,并有示例:https: //imapx.codeplex.com/wikipage?title=Sample%20code%20for%20get%20messages%20from%20your%20inbox
回答by user1662990
In the hope that it will be useful to some, you may want to check out my go at it:
希望它对某些人有用,您可能想查看我的操作:
While there are a couple of good and well-documented IMAP libraries for .NET available, none of them are free for personal, let alone commercial use...and I was just not all that satisfied with the mostly abandoned free alternatives I found.
虽然有一些用于 .NET 的良好且有据可查的 IMAP 库可用,但它们都不是免费供个人使用的,更不用说商业用途了……而且我对我发现的大部分已废弃的免费替代品并不完全满意。
S22.Imap supports IMAP IDLE notifications as well as SSL and partial message fetching. I have put some effort into producing documentationand keeping it up to date, because with the projects I found, documentation was often sparse or non-existent.
S22.Imap 支持 IMAP IDLE 通知以及 SSL 和部分消息获取。我付出了一些努力来制作文档并使其保持最新状态,因为在我发现的项目中,文档通常很少或根本不存在。
Feel free to give it a try and let me know if you run into any issues!
随意尝试一下,如果您遇到任何问题,请告诉我!