Helpful POP3 and IMAP Exchange 2010 links

Here is the list of some helpful links regarding IMAP and POP3 protocols in Exchange 2010:

Enable IMAP4 in Exchange 2010

Enable POP3 in Exchange 2010

Managing POP3 and IMAP4 in Exchange 2010

Understanding POP3 and IMAP4

Public folders and IMAP

Accessing shared and delegated mailboxes

Delete email permanently in Gmail

If you delete a message from your Inbox or one of your custom folders, it will still appear in [Gmail]/All Mail.

Here’s why: in most folders, deleting a message simply removes that folder’s label from the message, including the label identifying the message as being in your Inbox.

[Gmail]/All Mail shows all of your messages, whether or not they have labels attached to them.

If you want to permanently delete a message from all folders:

  1. Move it to the [Gmail]/Trash folder (or [Gmail]/Bin or national version).
  2. Delete it from the [Gmail]/Trash folder (or [Gmail]/Bin or national version).

All emails in [Gmail]/Spam and [Gmail]/Trash are deleted after 30 days.
If you delete a message from [Gmail]/Spam or [Gmail]/Trash, it will be deleted permanently.

Here’s how this looks like using Mail.dll .NET IMAP component:

Delete emails permanently (C# version)

// C# version:

using(Imap imap = new Imap())
{
	imap.ConnectSSL("imap.gmail.com");
	imap.UseBestLogin("user@gmail.com", "password");

	// Recognize Trash folder
	List<FolderInfo> folders = imap.GetFolders();
 	CommonFolders common = new CommonFolders(folders);
 	FolderInfo trash = common.Trash;

	// Find all emails we want to delete
	imap.SelectInbox();
	List<long> uids = imap.Search(
		Expression.Subject("email to delete"));

	// Move email to Trash
	List<long> uidsInTrash = new List<long>();
	foreach (long uid in uids)
	{
		long uidInTrash = (long)imap.MoveByUID(uid, trash);
		uidsInTrash.Add(uidInTrash);
	}

	// Delete moved emails from Trash
	imap.Select(trash);
	foreach (long uid in uidsInTrash)
	{
		imap.DeleteMessageByUID(uid);
	}

	imap.Close();
}

Delete emails permanently (VB.NET version)

Using imap As New Imap()
	imap.ConnectSSL("imap.gmail.com")
	imap.UseBestLogin("user@gmail.com", "password")

	' Recognize Trash folder
	Dim folders As List(Of FolderInfo) = imap.GetFolders()
	Dim common As CommonFolders = new CommonFolders(folders)
	Dim trash As FolderInfo = common.Trash

	' Find all emails we want to delete
	imap.SelectInbox()
	Dim uids As List(Of Long) = imap.Search( _
		Expression.Subject("email to delete"))

	' Move email to Trash
	Dim uidsInTrash As New List(Of Long)
	For Each uid As Long In uids
		Dim uidInTrash As Long = imap.MoveByUID(uid,trash)
		uidsInTrash.Add(uidInTrash)
	Next

	' Delete moved emails from Trash
	imap.[Select](trash)
	For Each uid As Long In uidsInTrash
		imap.DeleteMessageByUID(uid)
	Next

	imap.Close()
End Using

You can also use bulk methods to handle large amount of emails faster:

Delete emails permanently in bulk (C# version)

using(Imap imap = new Imap())
{
	imap.ConnectSSL("imap.gmail.com");
	imap.UseBestLogin("user@gmail.com", "password");

	// Recognize Trash folder
	List<FolderInfo> folders = imap.GetFolders();
 	CommonFolders common = new CommonFolders(folders);
 	FolderInfo trash = common.Trash;

	// Find all emails we want to delete
	imap.SelectInbox();
	List<long> uids = imap.Search(
		Expression.Subject("email to delete"));

	// Move emails to Trash
	List<long> uidsInTrash = imap.MoveByUID(uids, trash);

	// Delete moved emails from Trash
	imap.Select(trash);
	imap.DeleteMessageByUID(uidsInTrash);

	imap.Close();
}

Delete emails permanently in bulk (VB.NET version)

Using imap As New Imap()
	imap.ConnectSSL("imap.gmail.com")
	imap.UseBestLogin("user@gmail.com", "password")

	' Recognize Trash folder
	Dim folders As List(Of FolderInfo) = imap.GetFolders()
	Dim common As CommonFolders = new CommonFolders(folders)
	Dim trash As FolderInfo = common.Trash

	' Find all emails we want to delete
	imap.SelectInbox()
	Dim uids As List(Of Long) = imap.Search( _
		Expression.Subject("email to delete"))

	' Move email to Trash
	Dim uidsInTrash As List(Of Long) = imap.MoveByUID(uids, trash)

	' Delete moved emails from Trash
	imap.[Select](trash)
	imap.DeleteMessageByUID(uidsInTrash)

	imap.Close()
End Using

Please also note that there are 2 additional sections in the “Gmail settings”/”Forwarding and POP/IMAP” tab:

“When I mark a message in IMAP as deleted:”

  • Auto-Expunge on – Immediately update the server. (default)
  • Expunge off – Wait for the client to update the server.

“When a message is marked as deleted and expunged from the last visible IMAP folder:”

  • Archive the message (default)
  • Move the message to the Trash
  • Immediately delete the message forever

Those settings change the default behavior of the account and modify DeleteMessage* methods behavior.

Enable IMAP in Gmail

When it comes to managing emails efficiently, having the right tools can make all the difference.

Mail.dll is a helpful email library that can simplify email tasks for developers and businesses.

To make the most of Mail.dll’s capabilities, it’s essential to enable IMAP (Internet Message Access Protocol) in Gmail. Don’t worry; it’s not as complicated as it sounds!

In this article, we’ll guide you through the simple steps of enabling IMAP in Gmail, allowing you to seamlessly connect Mail.dll to your Gmail account. By doing so, you’ll unlock a world of convenient email management and boost your productivity.

Let’s explore how you can enable IMAP in Gmail and unleash the full potential of Mail.dll!

5 easy steps to enable IMAP

  • Sign in to Gmail.
  • Click the gear icon in the upper-right and select Settings.
  • Click Forwarding and POP/IMAP.
  • Select Enable IMAP.
  • Remember that Gmail only allows secure TLS/SSL connections so you need to use ConnectSSL method.

Application specific passwords

An application specific password is a 16-digit password that gives an application permission to access your Google Account. Application passwords are the easiest way to log-in to your Gmail account using POP3 or IMAP.

2-Step-Verification must be enabled on your account to access this feature (you’ll get the ‘setting you are looking for is not available for your account’ error otherwise):

Once you have the password use it as a regular password for POP3, SMTP or IMAP clients: using app passwords with Gmail

OAuth 2.0

Another approach would be to use one of the OAuth 2.0 flows:

  1. OAuth 2.0 for installed applications
  2. OAuth 2.0 for web applications
  3. OAuth 2.0 for service accounts

Less secure apps (deprecated)

On May 30, 2022, this setting will no longer be available.

Less secure apps (those that use primary password to access) are no longer supported by Gmail, except for some corporate accounts. You can find this setting here: enable access for ‘less’ secure apps 

Please note that contrary to what the label says those applications are secure – they use TLS to secure the communication. The term ‘less secure apps’ is used only because such applications need to be provided with account’s primary password to be able to access IMAP.

2-step verification

If you use 2-Step-Verification and are seeing a “password incorrect” error when trying to access IMAP, POP3, SMTP, an app password (or OAuth 2.0 access) will solve the problem. 

Simple .NET IMAP access sample

Discover the power of simple .NET IMAP access with Mail.dll’s user-friendly and efficient. This comprehensive and straightforward sample allows developers to effortlessly interact with IMAP servers in their .NET applications.

With Mail.dll’s intuitive API design, handling email tasks, such as parsing, composing, and managing folders, becomes a breeze. Whether you’re a seasoned developer or a newcomer to email integration, Mail.dll provides an excellent starting point for leveraging IMAP capabilities in your .NET projects. Say goodbye to complex implementations and embrace the ease and effectiveness of Mail.dll’s Simple .NET IMAP access sample.

// C# code:
 
using(Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "app-password");
 
    imap.SelectInbox();
 
    List<long> uids = imap.Search(Flag.Unseen);
    foreach (long uid in uids)
    {
        var eml = imap.GetMessageByUID(uid);
        IMail mail = new MailBuilder().CreateFromEml(eml);
 
        string subject = mail.Subject;
        string plainText = mail.Text;
    }
    imap.Close();
}
' VB.NET code:
 
Using imap As New Imap()
    imap.ConnectSSL("imap.gmail.com")
    imap.UseBestLogin("pat@gmail.com", "app-password")
 
    imap.SelectInbox()
 
    Dim uids As List(Of Long) = imap.Search(Flag.Unseen)
    For Each uid As Long In uids
        Dim eml = imap.GetMessageByUID(uid)
        Dim mail As IMail = New MailBuilder().CreateFromEml(eml)
 
        Dim subject As String = mail.Subject
        Dim plainText As String = mail.Text
    Next
    imap.Close()
End Using

You can find more .NET IMAP samples.

You can download Mail.dll IMAP library for .NET here.

Enable POP3 in Gmail

  • Sign in to Gmail.
  • Click the gear icon in the upper-right and select Settings.
  • Click Forwarding and POP/IMAP.
  • Select Enable POP for all mail or Enable POP for mail that arrives from now on. Here you can learn more about Gmail’s POP3 behavior
  • Remember that Gmail only allows secure TLS/SSL connections so you need to use ConnectSSL method.

Application specific password

An application specific password is a 16-digit password that gives an application permission to access your Google Account. Application passwords are the easiest way to log-in to your Gmail account using POP3 or IMAP.

2-Step-Verification must be enabled on your account to access this feature (you’ll get the ‘setting you are looking for is not available for your account’ error otherwise):

Once you have the password use it as a regular password for POP3, SMTP or IMAP clients.

OAuth 2.0

Another approach would be to use one of the OAuth 2.0 flows:

  1. OAuth 2.0 for installed applications
  2. OAuth 2.0 for web applications
  3. OAuth 2.0 for service accounts

Less secure apps (deprecated)

Less secure apps (those that use primary password to access) are no longer supported by Gmail, except some corporate accounts. You can find this here: enable access for ‘less’ secure apps 

Please note that contrary to what the label says those applications are secure – they use TLS to secure the communication. The term ‘less secure apps’ is used only because such applications need to be provided with account’s primary password to be able to access IMAP.

2-step verification

If you use 2-Step-Verification and are seeing a “password incorrect” error when trying to access POP3, IMAP, SMTP, an app password (or OAuth 2.0 access) will solve the problem. 

Simple .NET POP3 access sample

// C# code:
 
using(Pop3 pop3 = new Pop3())
{
    pop3.ConnectSSL("pop.gmail.com");
    pop3.Login("your_email@gmail.com", "app-password");
 
    foreach (string uid in pop3.GetAll())
    {
        var eml = pop3.GetMessageByUID(uid);
        IMail mail= new MailBuilder()
            .CreateFromEml(eml);
 
        Console.WriteLine(mail.Subject);
        Console.WriteLine(mail.Text);
    }
    pop3.Close();
}
' VB.NET code:
 
Using pop3 As New Pop3()
    pop3.ConnectSSL("pop.gmail.com")
    pop3.Login("your_email@gmail.com", "app-password")
 
    For Each uid As String In pop3.GetAll()
        Dim email As IMail = New MailBuilder() _
            .CreateFromEml(pop3.GetMessageByUID(uid))
        Console.WriteLine(email.Subject)
    Console.WriteLine(mail.Text)
    Next
    pop3.Close()
End Using

More .NET POP3 client samples. You can download Mail.dll IMAP library for .NET here.

livemail.co.uk SMTP bug

Recently one of our clients reported an issue with the SMTP server they use. The problem occurred only in Mail.dll. Outlook was working correctly.

The exception we are getting is:

Limilabs.Client.ServerException: 5.5.1 Invalid command
at Limilabs.Client.SMTP.Smtp.[1](String [1], Boolean
)
at Limilabs.Client.SMTP.Smtp.LoginDIGEST(String user, String password)
at Limilabs.Client.SMTP.Smtp.UseBestLogin(String user, String password)
at ..Forms.ComposeEmailForm.SendEmail()

The SMPT settings are as follows:

Outgoing mail server: smtp.livemail.co.uk
Port: 587
Use SSL: false

After some investigation it turned out that livemail.co.uk incorrectly advertises CRAM-MD5 login method:

The server EHLO response is misleading:


S: 250-AUTH LOGIN PLAIN CRAM-MD5 DIGEST-MD5
S: 250-ENHANCEDSTATUSCODES
S: 250-8BITMIME
S: 250-DSN
S: 250 AUTH PLAIN LOGIN CRAM-MD5

Notice that it sends DIGEST-MD5 in first AUTH response and it doesn’t send it in the second one. Unfortunately Mail.dll uses the first response and it causes it to use CRAM:

C: AUTH DIGEST-MD5

the command fails, because it’s most likely not implemented by the server or not turned on:

S: 500 5.5.1 Invalid command

AUTH PLAIN and AUTH LOGIN methods do work without any problems

using (Smtp client = new Smtp())
{
    client.Connect("smtp.livemail.co.uk");
    client.Login("user", "pass");
    //...
    client.Close();
}
using (Smtp client = new Smtp())
{
    client.Connect("smtp.livemail.co.uk");
    client.LoginPLAIN("user", "pass");
    //...
    client.Close();
}