Working with IMAP, POP3, SMTP and .NET

Yesterday i had to make a little app which functionality was to download file attachments. The idea was simple. Find new mails, search for specific files, download them, mark letters as read, reconnect after some period of time. With current possibilities of .net you have to write your own client, with your own MIME parser... Of course to reinvent the wheel it's not very smart. What I found as third party library was . Very nice library with many features. Library is not free. The unregistered version is fully functional but puts sometimes on random mails' subject "Please purchase the license". If you are developing a serious project whit this kind of functionality this library is for you.

(Insist to say that my opinion is based only on my user experience and it's not an add)

Some sample code from the web-site:
All you need is to reference Mail.dll.



using Lesnikowski.Client.IMAP;
using Lesnikowski.Mail;
using Lesnikowski.Mail.Headers;
using Lesnikowski.Mail.Headers.Constants;
using System;

class Program
{
static void Main(string[] args)
{
Imap imap = new Imap();
imap.Connect("mail.host.com");

imap.User = "lesnikowski";
imap.Password = "password";
imap.Login();

imap.SelectInbox();
List uids = imap.SearchFlag(Flag.Unseen);
foreach (long uid in uids)
{
string eml = imap.GetMessageByUID(uid);
ISimpleMailMessage email = new SimpleMailMessageBuilder()
.CreateFromEml(eml);
Console.WriteLine(email.Subject);
Console.WriteLine(email.TextDataString);
}
imap.Close(true);
}
};




Easy and nice, right? :)

0 коментара:

Публикуване на коментар

top