Click here to Skip to main content
13,248,927 members (41,303 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 27 Sep 2012

IMAP and POP3 Clients in C#

, 28 Sep 2012
Rate this:
Please Sign up or sign in to vote.
IMAP & POP3 Clients C#. A library for intuitive ease of use of these two protocols.


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. 


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:

  • Gmail
  • Windows Live

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
    List<IEmail> Messages
    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("", "", "examplePass", 993, true);    
// I assume that 5 is the last "ID" readed by my client. 
// If I want to read all messages i use "ImapClient.LoadMessages();"
// To read all my messages loaded:
for (int i = 0; i < ImapClient.Messages.Count; i++)
    IEmail msm = (IEmail)ImapClient.Messages[i];
    // Load all infos include attachments
    Console.Writeline(msm.Date.ToString() + " - " + msm.From[0] + " - " + 
                      msm.Subject + " - " + msm.Attachments.Count);


27/09/2012 : First version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

D.Net Solutions
Software Developer (Senior) D.Net Solution
Italy Italy
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionDoes not read the attachment filename Pin
Member 1194702115-Nov-17 22:52
memberMember 1194702115-Nov-17 22:52 
Questionany way to delete an IMAP email message? Pin
dileepawijay6-Jan-16 7:15
memberdileepawijay6-Jan-16 7:15 
Questioncan anyone help me to use it? Pin
antani7421-Jul-15 5:47
memberantani7421-Jul-15 5:47 
AnswerRe: can anyone help me to use it? Pin
antani7422-Jul-15 1:51
memberantani7422-Jul-15 1:51 
GeneralRe: can anyone help me to use it? Pin
antani7422-Jul-15 3:40
memberantani7422-Jul-15 3:40 
GeneralRe: can anyone help me to use it? Pin
Dolby.Xiaowen24-Jul-15 0:43
memberDolby.Xiaowen24-Jul-15 0:43 
GeneralRe: can anyone help me to use it? Pin
antani7430-Jul-15 1:21
memberantani7430-Jul-15 1:21 
GeneralRe: can anyone help me to use it? Pin
Dolby.Xiaowen31-Jul-15 1:40
memberDolby.Xiaowen31-Jul-15 1:40 
QuestionDelete message Pin
rikdepeuter21-Jul-15 0:59
memberrikdepeuter21-Jul-15 0:59 
QuestionPlease help me to use it Pin
Member 1180220030-Jun-15 23:49
memberMember 1180220030-Jun-15 23:49 
AnswerRe: Please help me to use it Pin
antani7421-Jul-15 5:46
memberantani7421-Jul-15 5:46 
QuestionMarking Mails as Read Pin
Sa'eed Namdar21-Jun-15 22:06
memberSa'eed Namdar21-Jun-15 22:06 
AnswerRe: Marking Mails as Read Pin
yang2006010930-Sep-15 1:00
memberyang2006010930-Sep-15 1:00 
GeneralUsing this library for Email Client Pin
Sagar9J8728-May-15 22:54
memberSagar9J8728-May-15 22:54 
GeneralMy vote of 3 Pin
Afzaal Ahmad Zeeshan20-Aug-14 10:57
professionalAfzaal Ahmad Zeeshan20-Aug-14 10:57 
QuestionRich Text / HTML Pin
Jeff Dressing10-May-14 6:23
memberJeff Dressing10-May-14 6:23 
QuestionLineSizeExceededException Pin
steinster5-Mar-14 3:23
membersteinster5-Mar-14 3:23 
AnswerRe: LineSizeExceededException Pin
D.Net Solutions27-Mar-14 7:49
memberD.Net Solutions27-Mar-14 7:49 
GeneralRe: LineSizeExceededException Pin
steinster2-May-14 10:42
membersteinster2-May-14 10:42 
Questionthere is an Error Pin
heemanshubhalla10-Feb-14 3:52
memberheemanshubhalla10-Feb-14 3:52 
Questionplease give instructions to operate Pin
heemanshubhalla10-Feb-14 2:04
memberheemanshubhalla10-Feb-14 2:04 
QuestionCan't use - "Does not exist in the current context"? Pin
gajit13-Nov-13 5:05
membergajit13-Nov-13 5:05 
QuestionIMAP attachements from wrong emails Pin
jaboostinky6-Oct-13 15:51
memberjaboostinky6-Oct-13 15:51 
QuestionStato Messaggio Pin
Z@clarco4-Sep-13 4:44
memberZ@clarco4-Sep-13 4:44 
AnswerRe: Stato Messaggio Pin
D.Net Solutions21-Nov-13 3:45
memberD.Net Solutions21-Nov-13 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 28 Sep 2012
Article Copyright 2012 by D.Net Solutions
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid