53

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; });
6
  • 1
    Thanks for updating and providing details of your research. Commented Dec 8, 2008 at 14:06
  • +1; Had a very similar requirement. Thanks for doing the research.
    – tsilb
    Commented Dec 30, 2008 at 16:55
  • A small comment: I've tested several of the implementations mentioned,and had to use the latest daily from anmar.eu.org/projects/sharpmimetools/files/daily to get correct decoding of MIME. c#Mail failed to decode correctly non-ascii,and most others failed at utf8, q encoding or other detail. Commented Jan 3, 2009 at 2:40
  • I use SharpMimeTools in my app and it's very solid. Commented Jul 14, 2009 at 12:57
  • C#Mail was moved to higlabo.codeplex.com
    – Higty
    Commented Oct 20, 2011 at 13:44

15 Answers 15

28

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.

0
7

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

6

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

1
  • 4
    -1 because this answer doesn't really provide any useful instructions or links.
    – JYelton
    Commented Jun 1, 2011 at 17:20
3

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.

2

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

2

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

1

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.

1

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.

1
  • dasBlog uses Lesnikowski.Pawel.Mail.Pop3 (lesnikowski.com/mail). It is now a commercial product but the version in dasblog is still open source
    – TonyB
    Commented Nov 6, 2008 at 18:45
1

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.

1
  • oh yeah. Mime is a PITA! If it's all plaintext, tho, it's not too bad :) I hope for their sake it's plaintext :)
    – Nic Wise
    Commented Oct 25, 2008 at 17:46
1

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

0
1

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

1
  • there seems to be a rash of downvoting perfectly valid answers lately.
    – Brian
    Commented Feb 14, 2012 at 22:33
1

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

1

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.

1
  • 3
    I think you underestimate how tricky and varied MIME can be in the real world. Commented Jul 14, 2009 at 12:57
1

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

1
  • I too have just found that 'amazing' function, but I see images are missing from the new MailMessage and its Headers collection is empty, which makes me a little wary of it.
    – ProfK
    Commented May 3, 2015 at 11:19
0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.