Sending emails in C# is easy; for basic use cases you don’t need external resources to send a note because .NET BCL already ships it. On .Net Developer Center, there’s a short description how to do it.
Now, how to fetch the email? It turns out it is not that easy – it’s not supported by .Net BCL. I spent a while researching for the best library that matched my purposes and I want to share my views on a couple of components I looked at.
Note: Please bear in mind I was interested only in a small piece of functionality such library could provide. My need was only to fetch an email (in plain text) with attachments. That was supposed to be done via POP3. I was not really interested in features like advanced sending emails (e.g. email templates), request and delivery receipts, support for iCalendar, email in HTML, etc. To sum up, I did not test libraries from that angle and therefore this comparison will not suit needs of all developers.
WinToolZone has released CSLMail. It’s easy to use and quite convenient but I had two major problems:
- retrieve email body – problems with MIME format – the retrieved text contained equality characters in several places, and mixed line endings ‘\r\n’ vs. ‘=0A=0D’ (although each line of the email was prepared in exactly the same way). Combination of search/replace? Forget it – too risky
- attachment – when I was trying to fetch email with an attachment, the code just threw an exception (there was a problem with String.Substring call while fetching the message)
It is possible the problems were on my side only (e.g. mail server), but anyway, it didn’t work It’s a pity there’s hardly anything on internet about that component and I failed to get more help from the package I had downloaded from CSLMail homepage.
If you had similar problems or, on contrary, everything worked fine on your side, could you please share your opinions?
This library is available at sourceforge. I was able to fetch a TXT email with an attachment, but the email text was seen as an attachment (I could live with it) not anything like a body. The attachment, though, was not retrievable at all.
Again, maybe it’s my fault but I couldn’t fix it in a reasonable time. So I gave up again…
Mail.dll is not available for free but there’s an evaluation version available to download so before you buy it you can check how it works. That version adds an annoying string to email subject so, in general, if you can leave with it you can stick to it. However, I’m afraid for more professional use that’s not an option.
A few comments:
- fetching emails with attachments was really easy and worked like a charm
- automatic email parsing when fetched from server – I get exactly the same text Outlook displays
- extensive examples – series of use cases shown in dedicated Visual Studio solutions (available in the package) and a lot of useful information on the author’s blog
- it’s not free tool, but probably is worth its money; also evaluation version is available
C# Mail a.k.a. HiguchiMail
- available at CodePlex, for free
- no problems with fetching email with attachment; both email text and attachment easy to retrieve
- comment in source code is written by Japanese
- even if there’s a problem there are lots of posts on discussion forum
In my opinion Mail.dll and C# Mail are the winners in this competition. Perhaps the former is more advanced, better documented, and even easier to use. It might fit better for commercial / more advanced use. However for basic actions with POP3 you can save a few Euro and go for free C# Mail.