Connect a Gmail mailbox

Gmail no longer accepts the account's usual password for IMAP and SMTP connections. You need an app password: a separate password, generated by Google, dedicated to a single application and revocable independently.

The procedure takes five minutes and requires no intervention on the Dolibarr server.

Step 1 -- Enable 2-step verification

This is a Google prerequisite: without it, the app passwords menu does not appear.

  1. Open myaccount.google.com/security.
  2. Section How you sign in to Google, click 2-Step Verification.
  3. Follow the wizard (phone number or authenticator app).

On a Google Workspace account (professional address), the domain administrator may have disabled app passwords. If the option remains impossible to find while 2-step verification is active, this is the restriction to lift with them.

Step 2 -- Enable IMAP in Gmail

  1. Open Gmail, then the gear at the top right, See all settings.
  2. Forwarding and POP/IMAP tab.
  3. IMAP access section: tick Enable IMAP.
  4. Save changes at the bottom of the page.

Step 3 -- Generate the app password

  1. Open myaccount.google.com/apppasswords.
  2. Give an explicit name, for example Dolibarr Capmail. This name is only used so you can find it later to revoke it.
  3. Validate: Google displays a 16-character password in four groups of four.
  4. Copy it immediately, it will not be shown again.

The spaces displayed by Google are decorative: you can enter the password with or without them, both work.

Step 4 -- Create the mailbox in Capmail

Administration > Capmail > Mailboxes > New mailbox.

IMAP section

Field Value
Label the name of your choice, e.g. Gmail Contact
Host imap.gmail.com
Port 993
Encryption SSL
Login your full address, e.g. contact@example.com
Password the app password from step 3
Main folder INBOX

Click Test IMAP connection. The test lists the folders actually present on the account: this list is authoritative for the next step.

Gmail special folders

Gmail stores its special folders under a [Gmail]/ prefix, and translates them into the account language. On an English account:

Capmail field English Gmail value
Sent folder [Gmail]/Sent Mail
Trash folder [Gmail]/Trash
Spam folder [Gmail]/Spam
Archive folder leave empty (see below)

On a French account, it will be [Gmail]/Messages envoyés, [Gmail]/Corbeille, [Gmail]/Spam.

Do not copy this table blindly: use the exact names displayed by the Test IMAP connection button. An account configured in another language, or a customized Google Workspace, will have different names.

Never use [Gmail]/All Mail as the archive folder. This folder is not an archive: it contains a copy of all the messages of the account, including those of the inbox. Designating it as source or target would cause massive duplicates.

SMTP section

Field Value
SMTP host smtp.gmail.com
SMTP port 465
SMTP encryption SSL
SMTP login leave empty (uses the IMAP login)
SMTP password leave empty (uses the IMAP password)

Click Test SMTP connection, then Save.

Step 5 -- Verify

  1. Send a test email to the Gmail address from another mailbox.
  2. In Capmail, click the collection button (refresh icon).
  3. The message must appear in the list.
  4. Reply to it from Capmail, then check in Gmail that the reply was actually sent and that it appears in "Sent Mail".

Gmail specifics to know

Gmail uses labels, not folders. A message carries one or more labels, which IMAP presents as folders. Consequence: the same message can appear in several places, and "moving" it means changing its label.

Archiving, in Gmail, means removing the "Inbox" label. The message is not moved elsewhere, it stays in "All Mail". This is why it is recommended to leave the archive folder empty: Capmail archiving then stays local, which is the most predictable behavior.

Deletion goes through the trash. A deleted message goes to [Gmail]/Trash, from where Gmail automatically purges it after 30 days.

Google limits access. A Gmail account tolerates a limited number of simultaneous IMAP connections and a daily download volume. On a very large mailbox, space out the collection frequency rather than setting it to the shortest.

In case of failure

Message Cause Solution
AUTHENTICATIONFAILED Invalid credentials the account password was used instead of the app password redo step 3
535-5.7.8 Username and Password not accepted same, on the SMTP side redo step 3
IMAP connection refused without a clear message IMAP disabled in Gmail redo step 2
The app passwords menu cannot be found 2-step verification inactive, or Workspace restriction step 1, then see the domain administrator

Without an app password?

If your Google Workspace administrator forbids app passwords, connect the mailbox via OAuth2: see Connect a Google or Microsoft 365 mailbox via OAuth.

What about Outlook or Microsoft 365?

Microsoft has removed password authentication on its IMAP and SMTP servers, including for personal Outlook.com accounts: the server answers Basic authentication is disabled. and no app password bypasses this restriction. These mailboxes are connected via OAuth2: see Connect a Google or Microsoft 365 mailbox via OAuth.