At a glance
- Sign-in: the user’s Gmail address plus a 16-character app password. Their normal Google password doesn’t work.
- Requires: 2-Step Verification on the Google account. For Google Workspace, the admin must allow IMAP and app passwords.
- Servers are filled in automatically for
@gmail.comand@googlemail.com. For Workspace (custom domains), useimap.gmail.comandsmtp.gmail.com. - “Continue with Google” (Google sign-in) isn’t offered. Gmail always connects with an app password.
How a user signs in to Gmail
An app password only works for mail (IMAP and SMTP). It can’t be used to sign in to the Google account, change settings or see other Google data. Revoking it disconnects only this integration.
Step 1: Turn on 2-Step Verification (the user)
App passwords exist only for accounts with 2-Step Verification.- Open myaccount.google.com/security.
- Under How you sign in to Google, open 2-Step Verification and turn it on (a phone, an authenticator app or a security key).
Accounts in Google’s Advanced Protection Program can’t create app passwords, so they can’t connect over IMAP.
Step 2: Create an app password (the user)
- Open myaccount.google.com/apppasswords. Google may ask for the password again.
- Type a name that says where it’s used, for example “CRM mailbox sync”, and click Create.
- Google shows a 16-character password (four groups of four letters), only once. Copy it, and enter it without the spaces.
- Use it in Step 3 instead of the normal password.
Step 2b: Google Workspace (company accounts, the admin)
For a mailbox on a company domain (ana@acme.com run by Google), the company’s Google Workspace admin must allow it once, in the Google Admin console:
Then each user does Steps 1 and 2 for their own account. Changes in the Admin console can take up to 24 hours to apply.
Step 3: Connect the mailbox
With the API
Your app asks the user for the Gmail address and the app password, then sends them withPOST /api/v1/auth/intent.
@gmail.comand@googlemail.comaddresses: the address and the app password are enough. The server settings are filled in for you.- Workspace addresses: pass
imap.gmail.comandsmtp.gmail.com(below).
201), and an account.add event is sent with your state. If Google rejects the password, the answer is 401 errors/invalid_credentials and nothing is saved. Show your user a reminder to use an app password, not their normal Google password.
To also import recent mail, add an initial sync: "config": { "initial_sync_enable": true, "initial_sync_days": 30 }.
From the dashboard
In the dashboard, open Accounts → Add account, enter the Gmail address and the app password, and save. For Workspace addresses, also enterimap.gmail.com and smtp.gmail.com in the server settings. See From the dashboard.
Server settings
SMTP on port
587 with STARTTLS works too.
How Gmail behaves over IMAP
Labels are folders
Gmail has labels, not folders. Over IMAP, Gmail shows each label as a folder:Moving, archiving and deleting
- Moving to a folder through the API (
PATCH /emails/{id}withfolder) moves it in Gmail: that label is added and the old one removed. - Archiving in Gmail removes the Inbox label. Over IMAP the email leaves
INBOX, so you getemail.deletefor the Inbox copy. It’s still in Gmail’s All Mail, which isn’t synced. - Deleting through the API (
DELETE /emails/{id}) moves it to[Gmail]/Trash, and you getemail.updatewithrole: "TRASH". Gmail empties the Trash after 30 days.
Sending
Emails sent through the API go out throughsmtp.gmail.com from the user’s address. Gmail saves the copy in Sent Mail itself, so the engine doesn’t save a second one. The copy then syncs back with email.new and role: "SENT". To send from another address, it must be set up in Gmail as a “Send mail as” alias.
Real-time
The engine keeps an IMAP IDLE connection on the Inbox, so new mail there arrives within a few seconds. Other folders (Sent, labels, Spam) are checked every 30 seconds, and Sync now checks at once.Gmail limits
Security
- The app password is encrypted in the engine’s database and is never returned by the API or written to logs.
- To disconnect, delete the account (
DELETE /api/v1/accounts/{id}) and, as the user, revoke the app password at myaccount.google.com/apppasswords. - Changing the Google account password revokes every app password. The account then becomes
disconnected. The user creates a new app password, and you send it with the account’saccount_id(Reconnect or change settings), or a workspace admin enters it with Update connection on the account’s page in the dashboard.
Troubleshooting
See also
- Connect a mailbox: every setting, and other providers
- Initial sync: import the last 30 days when connecting
- Account status:
running,errored,disconnected