Recommendations for a .NET component to access an

2019-01-06 12:50发布

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?

11条回答
放荡不羁爱自由
2楼-- · 2019-01-06 13:19

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

查看更多
beautiful°
3楼-- · 2019-01-06 13:20

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

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-06 13:20

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

查看更多
仙女界的扛把子
5楼-- · 2019-01-06 13:21

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.

查看更多
老娘就宠你
6楼-- · 2019-01-06 13:22

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

查看更多
登录 后发表回答