Introduction
Searching on the web I was never able to find a library simple and effective way to manage email client with IMAP or POP3 without having to create a good wrapper.
So I decided to make available to the wrapper that is currently used to handle these two protocols.
Background
This library is a library wrapper of free Limisoft library (attached in the download).
Lumisoft web site
This library allows you to create a client or IMAP or POP3 is 100% compatible
with servers such as:
Servers Libero, AOL, Exchange, Yahoo, etc.. are still in testing and not sure the 100% working. The POP3 protocol
is implemented based on RFC 1939 Link .
The IMAP protocol is implemented based on the standard Internet Message Access Protocol - Version
4 rev1 Link .
Using the code
This simple library to be able to create basic client using the two protocols used in the web: IMAP and POP3
The library exposes two interfaces: IMailClient
and IMail
.
public interface IEmail
{
}
public interface IEmailClient
{
}
IEmail
is an instance of an email message on server. IEmailClient
is an instance of a POP3 or IMAP client.
To construct an instance of a client to be used the factory "EmailClientFactory
" passing the method "GetClient
" the type of protocol you want to use
public static class EmailClientFactory
{
public static IEmailClient GetClient(EmailClientEnum type)
{
if (type == EmailClientEnum.IMAP) return new IMAP_Wrapper();
if (type == EmailClientEnum.POP3) return new POP3_Wrapper();
return null;
}
}
The interface IMailClient
allows to manage the clients in the same way.
public interface IEmailClient
{
event EmailClient_OnMessagesLoaded OnMessagesLoaded;
bool IsConnected
{
get;
set;
}
List<IEmail> Messages
{
get;
set;
}
void Connect(String server, String User, String pass, int port, bool useSSl);
void Disconnect();
void SetCurrentFolder(String folder);
int GetMessagesCount();
void LoadMessages();
void LoadMessages(String start, String end);
void LoadRecentMessages(Int32 lastSequenceNumber);
}
Using the library
IEmailClient ImapClient = EmailClientFactory.GetClient(EmailClientEnum.IMAP);
ImapClient.Connect("imap.gmail.com", "example@gmail.com", "examplePass", 993, true);
ImapClient.SetCurrentFolder("INBOX");
ImapClient.LoadRecentMessages(5);
for (int i = 0; i < ImapClient.Messages.Count; i++)
{
IEmail msm = (IEmail)ImapClient.Messages[i];
msm.LoadInfos();
Console.Writeline(msm.Date.ToString() + " - " + msm.From[0] + " - " +
msm.Subject + " - " + msm.Attachments.Count);
}
History
27/09/2012 : First version 1.0.0.0.