More .NET libraries
-
Rebex Mail Pack
IMAP, MS Graph, EWS, POP3, SMTP, MIME, S/MIME, MSG
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Easy-to-use API
On this page:
A typical IMAP session goes through the following steps:
- Connect to an IMAP server.
- Validate the server certificate (this is done automatically by default, but you can perform the validation yourself).
- Log in - if required, authenticate with a user name and password or using a certificate.
- Select a folder, find email messages, download messages, etc.
- Disconnect.
Getting list of unread emails using IMAP
The following code finds all unread e-mail messages and prints information about each of them:
// create IMAP client instance using (var imap = new Rebex.Net.Imap()) { // connect to Gmail IMAP server imap.Connect("imap.gmail.com", SslMode.Implicit); // authenticate imap.Login(username, password); // select folder to work with imap.SelectFolder("INBOX"); // get list of unread messages ImapMessageCollection list = imap.Search(ImapSearchParameter.Unread); // print some info foreach (ImapMessageInfo info in list) { Console.WriteLine("From: {0}", info.From); Console.WriteLine("To: {0}", info.To); Console.WriteLine("Subject: {0}", info.Subject); } // disconnect (not required, but polite) imap.Disconnect(); }
' create IMAP client instance Using imap = New Rebex.Net.Imap() ' connect to Gmail IMAP server imap.Connect("imap.gmail.com", SslMode.Implicit) ' authenticate imap.Login(username, password) ' select folder to work with imap.SelectFolder("INBOX") ' get list of unread messages Dim list As ImapMessageCollection = imap.Search(ImapSearchParameter.Unread) ' print some info For Each info As ImapMessageInfo In list Console.WriteLine("From: {0}", info.From) Console.WriteLine("To: {0}", info.To) Console.WriteLine("Subject: {0}", info.Subject) Next ' disconnect (not required, but polite) imap.Disconnect() End Using
Note: Although implicit SSL mode has been discouraged since 1999 (see RFC 2595) Gmail and some other providers still only supports this mode. Explicit mode should be used instead when available.
Back to feature list...