16

I've been asked to write a Windows service in C# to periodically monitor an email inbox and insert the details of any messages received into a database table.

My instinct is to do this via POP3 and sure enough, Googling for ".NET POP3 component" produces countless (ok, 146,000) results.

Has anybody done anything similar before and can you recommend a decent component that won't break the bank (a few hundred dollars maximum)?

Would there be any benefits to using IMAP rather than POP3?

Ian Nelson
  • 57,123
  • 20
  • 76
  • 103
  • https://github.com/jstedfast/MailKit is a good and active option. – Rory Nov 25 '15 at 00:50
  • Check also the following Mail Component for NET Review http://www.thedownloadplanet.com/reviews/review-mail-component-for-net/ You can see there examples of using IMAP, POP3 and SMTP – alexanoid Jun 24 '18 at 08:35

11 Answers11

6

I use the free and open source SharpMimeTools in my application, BugTracker.NET. It has been very dependable:

http://anmar.eu.org/projects/sharpmimetools/

See the files POP3Client.cs, POP3Main.cs, and insert_bug.aspx

Corey Trager
  • 22,649
  • 18
  • 83
  • 121
6

With IMAP protocol you can access sub folders, and set message status (seen/unseen), also you can use IDLE feature for instant notifications.

Mail.dll includes POP3, IMAP, SMTP components with SSL support and powerful MIME parser:

using(Imap imap = new Imap())
{
    imap.Connect("imap.server.com");    // or ConnectSSL for SSL
    imap.Login("user", "password");

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

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

You can download it at https://www.limilabs.com/mail

Pawel Lesnikowski
  • 6,264
  • 4
  • 38
  • 42
4

I recomment chilkat. They have pretty stable components, and you can get their email component for as cheap as $99 for a single developer. Personally, I think going with the whole package of components is a better deal, as it's only $289, and comes with many useful components. I'm not affiliated with them in any way, although I probably sound like I am.

Kibbee
  • 65,369
  • 27
  • 142
  • 182
  • My only complaint with Chilkat is the API doesn't "feel" very .Net (if you know what I mean). e.g. "GetLastError()" instead of an exception. Great components though and a great price. Support is absolutely top-notch as well, wonderfully quick turn-around during the times I've had questions. – Adrian Clark Sep 30 '08 at 05:43
  • 1
    That's probably due to the fact that it's an older library that's been ported to .Net. – Kibbee Jan 08 '09 at 01:40
  • 3
    Exceptions sure "feel" .net, but it's worth to comment that Google Code Guidelines uses error codes and assertions instead of exceptions. They also make it clear in the document that they don't really feel that using Exceptions is 'wrong', but they do provide some good reasons not to. – Rafael Almeida Aug 04 '09 at 01:19
3

You may want to check our Rebex Mail component. It includes IMAP, SMTP, POP3 protocols and and S/MIME parser.

The POP3 does not have a concept of 'unread' messages or searchig for messages matching specific criteria. POP3 simply returns all messages in your inbox.

Using IMAP you can instruct the IMAP server to send you just unread messages, messages which arrived since specified time, messages from specific user etc. You don't have to download it all to the client and do the filtering there.

Following code shows how to download unread messages from the Imap server using Rebex.Net.Imap class.

// create client, connect and log in 
Imap client = new Imap();
client.Connect("imap.example.org");
client.Login("username", "password");

// select folder 
client.SelectFolder("Inbox");

// get message list - envelope headers 
ImapMessageCollection messages = client.Search
  (
     ImapSearchParameter.HasFlagsNoneOf(ImapMessageFlags.Seen)
  ); 

// display info about each message 
Console.WriteLine("UID | From | To | Subject");
foreach (ImapMessageInfo message in messages)
{
    Console.WriteLine(
        "{0} | {1} | {2} | {3}",
        message.UniqueId,
        message.From,
        message.To,
        message.Subject);
}

// disconnect 
client.Disconnect();

Example of combining multiple search criteria follows. This will return messages from the last year larger than 100KB.

ImapMessageCollection messages = client.Search
  (
     ImapSearchParameter.Arrived(DateTime.Now.AddYears(-1), DateTime.Now),
     ImapSearchParameter.Size(1024 * 100, Int32.MaxValue)
  ); 

You can download the trial from rebex.net/secure-mail.net/download.aspx

Martin Vobr
  • 5,757
  • 2
  • 37
  • 43
  • Leave a disclaimer that this is your product. – Dominic K Jul 13 '11 at 00:39
  • 1
    @DMan: It's already there in the very first line for almost year now ("You may want to check __our__ Rebex Mail..."). I'm not trying to hide my connection. Suggestion how to improve it are welcome (English is not my first language). – Martin Vobr Jul 14 '11 at 22:44
  • sorry, I missed that subtlety. My apologies. – Dominic K Jul 15 '11 at 03:35
3

I would recommend AdvancedIntellect. There are components for POP3 and IMAP (ASPNetPOP3 and ASPNetIMAP). Good quality and very responsive support - I remember receiving replies to my questions on a weekend.

splattne
  • 102,760
  • 52
  • 202
  • 249
2

If you use an open source POP3 implementation or something freely available then you will have access to modify the code and expand it in the direction needed. A quick Google resulted in this C# POP3 code from Code Project to retrieve messages.

There's something empowering about rolling your own, or at least extending it.

alt text

Community
  • 1
  • 1
John K
  • 28,441
  • 31
  • 139
  • 229
  • Also this won't break the bank as far as initial cost $0. However ongoing development work and overall "TCO" should be considered. – John K Oct 21 '09 at 22:24
1

Lumisoft is open-source and includes IMAP and POP clients (among other stuff). I've been using them for years with no problems.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
0

You can do this using MailBee.NET Objects: http://www.afterlogic.com/products/net-email-components

While I'd recommend to use IMAP indeed, particularly since it offers IDLE support mentioned here already, you could do the same with POP3. There's a brief description of both the approaches, and a complete sample for IMAP IDLE scenario:

http://www.afterlogic.com/wiki/Getting_notifications_about_new_messages_in_mailbox_%28IMAP_IDLE_and_polling%29

Please note that I am affiliated with AfterLogic, and I'll be pleased to assist you if you need any help, check Request Support option at our website.

0

How about WCF? It's free.

If you have an Exchange server: http://msdn.microsoft.com/en-us/library/bb397812.aspx

an example for pop3: http://bartdesmet.net/blogs/bart/archive/2006/09/13/4417.aspx

Sven Hecht
  • 1,337
  • 1
  • 16
  • 23
0

IMAPX2 is the best. Using IMAP you can control the folders in a mail server, a thing you wouldn't be able to do using POP. IMAPX is an open source code you can look into, and is free to use.

IMAPX is straight forward and reliable.

Falah Abu Hassan
  • 105
  • 2
  • 11
0

C#Mail cost $0 but is also GNU GPL licenced, so make sure that's OK.

jmd
  • 877
  • 8
  • 12