Dom*_*c K 88
我一直在寻找IMAP解决方案一段时间,经过不少尝试后,我将选择AE.Net.Mail.
您可以通过转到"代码"选项卡并单击小的"下载"图标来下载代码.由于作者未提供任何预先构建的下载,您必须自己编译.(我相信你可以通过NuGet获得它).bin /文件夹中不再有.dll.
没有文档,我认为这是一个缺点,但我能够通过查看源代码(yay for open source!)和使用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", "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();
Run Code Online (Sandbox Code Playgroud)
请务必查看Github页面以获取最新版本和一些更好的代码示例.
Paw*_*ski 18
IMAP没有.NET框架支持.您需要使用一些第三方组件.
试试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);
}
Run Code Online (Sandbox Code Playgroud)
请注意,这是我创建的商业产品.
您可以在此处下载:https://www.limilabs.com/mail.
小智 14
MailSystem.NET包含您对IMAP4的所有需求.它是免费和开源的.
(我参与了这个项目)
我自己还没有尝试过,但这是一个免费的库,你可以尝试一下(我不太确定这个库的 SSL 部分):
http://www.codeproject.com/KB/IP/imaplibrary.aspx
另外,还有 xemail,它具有 SSL 参数:
http://xemail-net.sourceforge.net/
[编辑]如果您(或客户)有钱购买专业的邮件客户端,此线程有一些很好的建议: