.net 将 POP3 客户端功能集成到 C# 应用程序中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/236381/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 10:25:40  来源:igfitidea点击:

Integrating POP3 client functionality into a C# application?

.netpop3review

提问by flesh

I have a web application that requires a server based component to periodically access POP3 email boxes and retrieve emails. The service then needs to process the emails which will involve:

我有一个 Web 应用程序,它需要一个基于服务器的组件来定期访问 POP3 邮箱和检索电子邮件。然后该服务需要处理涉及以下内容的电子邮件:

  • Validating the email against some business rules (does it contain a valid reference in the subject line, which user sent the mail, etc.)
  • Analysing and saving any attachments to disk
  • Take the email body and attachment details and create a new item in the database
  • Or update an existing item where the reference matches the incoming email subject line
  • 根据某些业务规则验证电子邮件(它是否在主题行中包含有效的引用、用户发送的邮件等)
  • 分析任何附件并将其保存到磁盘
  • 获取电子邮件正文和附件详细信息并在数据库中创建一个新项目
  • 或更新引用与传入电子邮件主题行匹配的现有项目

What is the best way to approach this? I really don't want to have to write a POP3 client from scratch, but I need to be able to customize the processing of emails. Ideally I would be able to plug in some component that does the access and retrieval for me, returning arrays of attachments, body text, subject line, etc. ready for my processing...

解决这个问题的最佳方法是什么?我真的不想从头开始编写 POP3 客户端,但我需要能够自定义电子邮件的处理。理想情况下,我将能够插入一些为我进行访问和检索的组件,返回附件数组、正文、主题行等,为我的处理做好准备......

[ UPDATE: Reviews ]

[更新:评论]

OK, so I have spent a fair amount of time looking into (mainly free) .NET POP3 libraries so I thought I'd provide a short review of some of those mentioned below and a few others:

好的,所以我花了很多时间研究(主要是免费的).NET POP3 库,所以我想我会对下面提到的一些库和其他一些库进行简短的回顾:

  • Pop3.net- free - works OK, very basic in terms of functionality provided. This is pretty much just the POP3 commands and some base64 encoding, but it's very straight forward - probably a good introduction
  • Pop3 Wizard- commercial / some open source code - couldn't get this to build, missing DLLs, I wouldn't bother with this
  • C#Mail- free for personal use - works well, comes with Mime parser and SMTP client, however the comments are in Japanese (not a big deal) and it didn't work with SSL 'out of the box' - I had to change the SslStream constructor after which it worked no problem
  • OpenPOP- free - hasn't been updated for about 5 years so it's current state is .NET 1.0, doesn't support SSL but that was no problem to resolve - I just replaced the existing stream with an SslStream and it worked. Comes with Mime parser.
  • Pop3.net- 免费 - 工作正常,在提供的功能方面非常基本。这几乎只是 POP3 命令和一些 base64 编码,但它非常简单 - 可能是一个很好的介绍
  • Pop3 Wizard- 商业/一些开源代码 - 无法构建它,缺少 DLL,我不会为此烦恼
  • C#Mail- 免费供个人使用 - 运行良好,带有 Mime 解析器和 SMTP 客户端,但是注释是日语的(没什么大不了的)并且它“开箱即用”不能与 SSL 一起使用 - 我不得不更改 SslStream 构造函数之后它就没有问题了
  • OpenPOP- 免费 - 大约 5 年没有更新,所以它的当前状态是 .NET 1.0,不支持 SSL,但这没有问题可以解决 - 我只是用 SslStream 替换了现有的流并且它起作用了。带有 Mime 解析器。

Of the free libraries, I'd go for C#Mail or OpenPOP.

在免费库中,我会选择 C#Mail 或 OpenPOP。

I looked at a few commercial libraries: Chillkat, Rebex, RemObjects, JMail.net. Based on features, price and impression of the company I would probably go for Rebex and may in the future if my requirements change or I run into production issues with either of C#Mail or OpenPOP.

我查看了一些商业库:ChillkatRebexRemObjectsJMail.net。根据公司的功能、价格和印象,我可能会选择 Rebex,如果我的需求发生变化或者我在使用 C#Mail 或 OpenPOP 时遇到生产问题,我可能会选择 Rebex。

In case anyone's needs it, this is the replacement SslStream constructor that I used to enable SSL with C#Mail and OpenPOP:

如果有人需要它,这是我用来使用 C#Mail 和 OpenPOP 启用 SSL 的替代 SslStream 构造函数:

SslStream stream = new SslStream(clientSocket.GetStream(), false,
                 delegate(object sender, X509Certificate cert,
                 X509Chain chain, SslPolicyErrors errors) { return true; });

回答by foens

I am one of the main developers of OpenPop.NET. I just fell over this review, and had to come with some comments regarding the current state of OpenPop.NET as the review seems outdated with the development.

我是OpenPop.NET的主要开发人员之一。我刚刚看完这篇评论,不得不对 OpenPop.NET 的当前状态发表一些评论,因为评论似乎随着开发而过时了。

OpenPop.NET is back into active development. SSL has been introduced a half year back. The project had a major refactoring and is now much more stable and easy to use. When I took over the project it had a lot of bugs in it, and as of now I currently know none. A lot of extra features have been implemented, mainly in the MIME parser part. The project is backed by unit tests, and each time a bug is found, a unit test is created to show this bug before fixing it. An accompanying websitewith examples now exists. There has also been other updates, but I do not want to mention them all.

OpenPop.NET 重新进入活跃的开发阶段。SSL 已在半年前推出。该项目进行了重大重构,现在更加稳定和易于使用。当我接手这个项目时,它有很多错误,目前我不知道。已经实现了很多额外的功能,主要是在 MIME 解析器部分。该项目由单元测试支持,每次发现错误时,都会创建单元测试以在修复之前显示此错误。现在存在带有示例的随附网站。还有其他更新,但我不想全部提及。

Also, OpenPop.NET's license has been changed from LGPLto Public Domain(aka, no restrictions). This I think is a major improvement for commercial users.

此外,OpenPop.NET 的许可证已从LGPL更改为公共域(也就是无限制)。我认为这是对商业用户的重大改进。

回答by Jason Kester

I did an implementation of OpenPopfor a project recently, and was happy with it. It does what it says on the tin. (and it's free.)

我最近为一个项目做了一个OpenPop的实现,并且很满意。它做它在锡上所说的。(而且它是免费的。)

回答by Higty

The constructor of SslStream class was modified and uploaded. Recommended version have no problem to use.

修改并上传了 SslStream 类的构造函数。推荐版本使用没有问题。

回答by Steven Murawski

C# Mailis available on Codeplex and is pretty easy to use.

C# 邮件可在 Codeplex 上使用,并且非常易于使用。

回答by Pawel Lesnikowski

You may want to include Mail.dll .NET mail componentin your ranking. It has SSL support, Unicode, and multi-national email support:

您可能希望在排名中包含Mail.dll .NET 邮件组件。它具有 SSL 支持、Unicode 和多国电子邮件支持:

using(Pop3 pop3 = new Pop3())
{
    pop3.Connect("mail.host.com");      // Connect to server
    pop3.Login("user", "password");     // Login

    foreach(string uid in pop3.GetAll())
    {
        IMail email = new MailBuilder()
   .CreateFromEml(pop3.GetMessageByUID(uid));

        Console.WriteLine(email.Subject);
    }
    pop3.Close(true);  
}

IMAP protocol is also supported.

还支持 IMAP 协议。

Please note that this is a commercialproduct I've created.

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

You can download it here: http://www.lesnikowski.com/mail

你可以在这里下载:http: //www.lesnikowski.com/mail

回答by Oran Dennison

A new option (as of 2014) is MailKitfrom Xamarin, available under the MIT license. It parses messages from disk 25x faster than OpenPOP.NET. It includes support of IMAP, POP3, and SMTP and seems to be very fast and robust.

一个新选项(截至 2014 年)是Xamarin 的MailKit,在 MIT 许可下可用。它从磁盘解析消息的速度比 OpenPOP.NET 快 25 倍。它包括对 IMAP、POP3 和 SMTP 的支持,并且看起来非常快速和强大。

回答by JP Hellemons

Since I had to automate some email processing things. I took OpenPop.net I was searching how I could forward mailmessages with this library and came across this amazing function: http://hpop.sourceforge.net/documentation/OpenPop~OpenPop.Mime.Message.ToMailMessage.html

因为我不得不自动化一些电子邮件处理的事情。我使用了 OpenPop.net 我正在搜索如何使用这个库转发邮件消息并遇到了这个惊人的功能:http://hpop.sourceforge.net/documentation/OpenPop~OpenPop.Mime.Message.ToMailMessage.html

to summarize, I have chosen OpenPop.Netand recommend it!

总而言之,我选择了OpenPop.Net并推荐它!

best regards, JP

最好的问候,JP

回答by JP Hellemons

If you need SSL to access gmail.. here is some modifications to the OpenPOP.net library that gives it SSL support.

如果您需要 SSL 来访问 gmail.. 这里是对 OpenPOP.net 库的一些修改,使其支持 SSL。

OpenPop.net modified to include SSL support for accessing Gmail

OpenPop.net 修改为包含访问 Gmail 的 SSL 支持

回答by Corey Trager

Take a look at the POP3 integration in my open source app BugTracker.NET at http://ifdefined.com/bugtrackernet.html. All free and open source. The hardest part, the mime parsing, is done in BugTracker.NET by SharpMimeTools at http://anmar.eu.org/projects/sharpmimetools/

http://ifdefined.com/bugtrackernet.html 上查看我的开源应用程序 BugTracker.NET 中的 POP3 集成。全部免费和开源。最难的部分是 mime 解析,由 SharpMimeTools 在 BugTracker.NET 中完成,网址为http://anmar.eu.org/projects/sharpmimetools/

The important files that show how I'm using the POP3 and MIME logic are POP3Client.cs and insert_bug.aspx.

显示我如何使用 POP3 和 MIME 逻辑的重要文件是 POP3Client.cs 和 insert_bug.aspx。

回答by Nic Wise

DasBlog uses a good (and free) one - grab the source package. I've used it (but I can't remember who wrote it, and I'm not on my laptop - Pavel L I think?). It's not perfect, and it doesn't do SSL, but it works nicely otherwise.

DasBlog 使用了一个很好的(并且免费的) - 获取源包。我用过它(但我不记得是谁写的,而且我不在我的笔记本电脑上 - Pavel LI 认为?)。它并不完美,也不支持 SSL,但除此之外它运行良好。