Enable IMAP in Gmail

  • 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 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: 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

// 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);
 
        Console.WriteLine(mail.Subject);
        Console.WriteLine(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)
 
        Console.WriteLine(mail.Subject)
        Console.WriteLine(mail.Text)
    Next
    imap.Close()
End Using

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

Tags:  

Questions?

Consider using our Q&A forum for asking any questions.

2 Responses to “Enable IMAP in Gmail”

  1. Download unseen emails from Gmail Says:

    […] First remember to enable IMAP in Gmail. […]

  2. Archive email in Gmail Says:

    […] First remember to enable IMAP in Gmail. […]