views:

1552

answers:

9

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?

A: 

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
+4  A: 

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
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.
Aydsman
That's probably due to the fact that it's an older library that's been ported to .Net.
Kibbee
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
+4  A: 

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
Thanks Corey, I'll take a look.
Ian Nelson
I don't know where you got Pop3Client.cs from. I think SharpMimeTools is only a great Mime parsing only.
Sergej Andrejev
+2  A: 

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
+2  A: 

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
+1  A: 

C#Mail is easy to use It is a sample code for your needs

using (Pop3Client cl = new Pop3Client())
{
    cl.UserName = "MyUserName";
    cl.Password = "MyPassword";
    cl.ServerName = "MyServer";
    cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
    cl.Ssl = false;
    cl.Authenticate();
    ///Get first mail of my mailbox
    Int64 MailCount = cl.GetTotalMessageCount();
    if (MailCount > PreviousMailCount)
    {
        for (i=PreviousMailCount + 1; i<=MailCount; i++)
        {
            Pop3Message mg = cl.GetMessage(i);
            ///Data property return live mail data
            String YourData = mg.Data;
            ///Decode and output attachment file data to stream
            Pop3Content ct = mg.Contents[0];
            mg.DecodeData(YourStreamObject);
            ///Write your code to save database with YourData and YourStreamObject....
        }
    }
}

you can get it from codeplex

http://csharpmail.codeplex.com/

it costs only $0. And I hope your help.

Higty
A: 
John K
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
A: 

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

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

jmd