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

发布于 2024-07-07 12:25:40 字数 1994 浏览 5 评论 0 原文

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

  • 根据某些业务规则验证电子邮件(主题行中是否包含有效的引用、发送邮件的用户等)
  • 分析所有附件并将其保存到磁盘
  • 获取电子邮件正文和附件详细信息并在数据库中创建新项目
  • 或更新引用与传入电子邮件主题行匹配的现有项目

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

[更新:评论]

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

  • Pop3.net - 免费 - 工作正常,非常基本提供的功能条款。 这几乎只是 POP3 命令和一些 base64 编码,但它非常简单 - 可能是一个很好的介绍
  • Pop3 Wizard - 商业/一些开源代码 - 无法构建它,缺少 DLL,我不会为此烦恼
  • C#Mail - 免费供个人使用 - 效果很好,带有 Mime 解析器和 SMTP 客户端,但是注释是日语的(没什么大不了的)它不能与 SSL“开箱即用”一起使用 - 我必须更改 SslStream 构造函数,之后它就没有问题
  • OpenPOP - 免费 - 大约 5 年没有更新,所以它当前的状态是 .NET 1.0,不支持 SSL,但这不是要解决的问题 - 我只是用 SslStream 替换了现有的流,有效。 带有 Mime 解析器。

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

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

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

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

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:

  • 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...

[ 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:

  • 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.

Of the free libraries, I'd go for C#Mail or 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.

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

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

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

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

发布评论

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

评论(15

猫九 2024-07-14 12:25:41

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

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

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/

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

甜心小果奶 2024-07-14 12:25:41

我制作了自己的 Mime 解析器并将其添加到 CodePlex 中,因为当涉及奇怪的编码和奇怪的附件组合时,我不断遇到其他解析器未处理的异常。 pop3 客户端实现很粗糙,只是为了测试目的而设计的,但处理起来还可以。 Mime 解析器部分填充标准 MailMessage 对象,以便您可以轻松地按原样转发它。 我可以根据要求扩展/改进它,但目前它可以满足我的需求。 请随意检查一下。

http://www.codeplex.com/mimeParser

I made my own Mime parser and added it to CodePlex because I kept running into unhandled exceptions with the other ones when it came to strange encodings og weird combinations of attachments. The pop3 client implementation is crude, just made for testing purposes, but handles that ok. The Mime parser part populates the standard MailMessage object, so that you can easily forward it at it is. I can expand/improve it on request, but for now it does the job ok for my needs. Feel free to check it out.

http://www.codeplex.com/mimeParser

上课铃就是安魂曲 2024-07-14 12:25:41

Lumisoft 是开源的,包括 POP 客户端(以及其他内容) 。 已经用了很多年了,非常稳定。

Lumisoft is open-source and includes a POP client (among other stuff). It's been around for many years, very stable.

浅笑轻吟梦一曲 2024-07-14 12:25:41

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

OpenPop.net 已修改为包含 SSL 支持用于访问 Gmail

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

OpenPop.net modified to include SSL support for accessing Gmail

记忆消瘦 2024-07-14 12:25:41

codeproject.com 上有多种 POP3 客户端实现。 我还没有对它们进行评估,但也许你可以在那里找到你需要的东西。 如果没有,我可以说 POP3 是一个相当简单的协议。 如果您知道 4-5 个命令,您甚至可以使用 telnet 读取 POP3 框。

实际上,您只需要 this 命令以及一些附件的 Base64 解码。 就是这样。

There are several POP3 client implementations around at codeproject.com. I have not evaluated them, but maybe you can find what you need there. If not, I can say that POP3 is quite a simple protocol. You can even read your POP3 box with telnet if you know 4-5 commands.

You actually just need this commands and maybe some base64 decoding for attachments. That's it.

七秒鱼° 2024-07-14 12:25:41

因为我必须自动化一些电子邮件处理工作。 我选择了 OpenPop.net
我正在搜索如何使用这个库转发邮件消息,并发现了这个令人惊奇的功能: http://hpop.sourceforge.net/documentation/OpenPop~OpenPop.Mime.Message.ToMailMessage.html

总结一下,我选择了OpenPop.Net并推荐它!

此致,
J.P

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

to summarize, I have chosen OpenPop.Net and recommend it!

best regards,
JP

停滞 2024-07-14 12:25:41

如果您不介意购买组件,我们过去在 chilkat 方面取得了巨大成功。 只需花费几百美元,您就可以得到一个充满美好事物的图书馆。

If you don't mind paying for a component, we've had great success with chilkat in the past. For a couple of hundred bucks you get a library that's jam packed full of goodness.

很酷不放纵 2024-07-14 12:25:40

我是 OpenPop.NET 的主要开发人员之一。 我刚刚对这篇评论感到失望,并且不得不对 OpenPop.NET 的当前状态发表一些评论,因为这篇评论似乎已经过时了。

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

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

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 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 website with examples now exists. There has also been other updates, but I do not want to mention them all.

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

空城旧梦 2024-07-14 12:25:40

我最近为一个项目实现了 OpenPop,并且对此感到满意。 它的作用正如罐头上所说的那样。 (而且它是免费的。)

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

静赏你的温柔 2024-07-14 12:25:40

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

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

凌乱心跳 2024-07-14 12:25:40

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

A new option (as of 2014) is MailKit from 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.

已下线请稍等 2024-07-14 12:25:40

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

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

清泪尽 2024-07-14 12:25:40

您可能希望在排名中包含 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 协议。

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

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

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

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.

Please note that this is a commercial product I've created.

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

无力看清 2024-07-14 12:25:40

Jmail.NET。 别再往前看了。 请注意,免费版本不包括 POP3。 您需要使用标准版本(或更多版本)。 别担心,它并不贵。

Jmail.NET. Don't look further. Note that the free version doesn't include POP3. You'll want to take the Standard version (or more). Don't worry, it's not expensive.

榆西 2024-07-14 12:25:40

DasBlog 使用了一个很好的(而且免费的)方法——获取源码包。 我用过它(但我不记得是谁写的,而且我不在我的笔记本电脑上 - Pavel LI 认为?)。 它并不完美,并且不支持 SSL,但在其他方面它工作得很好。

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.

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