如何使用 C# 读取收到的邮件

发布于 2024-10-10 07:50:37 字数 1539 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

执手闯天涯 2024-10-17 07:50:37

如果您已经使用 Exchange 服务器作为邮箱主机,我建议您通过 IMAP(首选)或 POP 访问来利用它。最近我开发了一个通过 AfterLogic 的 MailBee.NET IMAP 组件 访问指定邮箱的解决方案我认为值得推荐。他们有标准的试用版和合理的定价。此外,如果您选择这种方式,POP 或 IMAP 自动化都足够灵活,可以与几乎所有邮箱服务器平台配合使用;它不必局限于 Exchange 环境。

还有免费的 .NET IMAP 组件也可以完成这项工作。在我有限的研究中,我发现免费的替代品并不能完全满足我的所有要求,或者不太容易学习,但您的情况可能有所不同。为了完整起见,这里列出了我在决定花钱购买 MailBee 之前考虑过的替代/免费 IMAP 库:

为了解决您问题的第二部分...我最近项目中的实现涉及编写一个引用 MailBee.NET IMAP 库的非常简单的控制台应用程序。控制台应用程序有一个标准配置文件并接受命令行参数作为参数。我们定义Windows计划任务来根据我们的流程需要运行控制台应用程序。我相信您可以通过许多其他方式来做到这一点,但这是满足我们需求的最简单方法。

If you are already dealing with an Exchange server as the mailbox host I would suggest leveraging that via IMAP (preferred) or POP access. Recently I developed a solution that accesses a specified mailbox via AfterLogic's MailBee.NET IMAP component which I think is worth the recommendation. They have a standard trial version and reasonable pricing. Also if you go this route either POP or IMAP automation is flexible enough to work with almost any mailbox server platform; It doesn't have to be limited to Exchange environments.

There are also free .NET IMAP components out there that may do the job as well. In my limited research I found that the free alternatives didn't quite meet all of my requirements or were not as easy to learn but your situation may differ. For completeness, here is a list of alternative / free IMAP libraries I considered before deciding to spend the money on MailBee:

To address the 2nd part of your question... The implementation in my recent project involved writing a very simple console application that references the MailBee.NET IMAP library. The console application has a standard config file and accepts command line arguments as parameters. We define Windows scheduled tasks to run the console application according to our process needs. I am sure you could do this any number of other ways but this was the simplest approach for our needs.

鸠魁 2024-10-17 07:50:37

我知道这是一个较旧的线程,但我想添加一个名为 ImapX2 的开源 Imap 库的链接: http://imapx.codeplex.com /

我尝试了该线程中的大部分链接,并取得了不同程度的成功,但我发现 ImapX2 库最适合我的需要。

I know this is an older thread but I wanted to add a link to a great open source Imap library called ImapX2: http://imapx.codeplex.com/

I tried most of the links in this thread to varying degrees of success but I found that the ImapX2 library work the best according to my needs.

记忆之渊 2024-10-17 07:50:37

为此,请使用现有的 IMAP 服务器和 IMAP 组件

在我看来,创建自己的 IMAP 服务器是一个很大的安全风险。

有免费组件,但大多数都存在国家字符和“不标准”电子邮件消息的问题...并且没有任何支持(LumiSoft.Net 已被放弃近 2 年)

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

    imap.SelectInbox();
    List<long> uidList = imap.Search(Flag.Unseen);
    foreach (long uid in uidList)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        Console.WriteLine(email.Subject);
        Console.WriteLine(email.Attachments.Count);
    }
    imap.Close();
}

Mail.dll 还包括 SMTP 组件和 模板引擎,以便您可以轻松发送回复。

免责声明:我参与了该商业产品的开发。

Use existing IMAP server and IMAP component for that.

Creating your own IMAP server is a big security risk in my opinion.

There are free components, but most of them have problems with national characters and 'not standard' email messages...and there is none support (LumiSoft.Net is abandoned for almost 2 years)

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

    imap.SelectInbox();
    List<long> uidList = imap.Search(Flag.Unseen);
    foreach (long uid in uidList)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        Console.WriteLine(email.Subject);
        Console.WriteLine(email.Attachments.Count);
    }
    imap.Close();
}

Mail.dll also includes SMTP component and template engine so you can send replies easily.

Disclaimer: I'm involved in the development of this commercial product.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文