Skip to main content
Gmail and Google Workspace mailboxes connect over IMAP and SMTP, signed in with a Google app password. The engine then syncs the mailbox like any IMAP account: new mail arrives in seconds, sending goes through Gmail’s SMTP server, and every change sends its webhook.
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.com and @googlemail.com. For Workspace (custom domains), use imap.gmail.com and smtp.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.
  1. Open myaccount.google.com/security.
  2. 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)

  1. Open myaccount.google.com/apppasswords. Google may ask for the password again.
  2. Type a name that says where it’s used, for example “CRM mailbox sync”, and click Create.
  3. Google shows a 16-character password (four groups of four letters), only once. Copy it, and enter it without the spaces.
  4. Use it in Step 3 instead of the normal password.
If App passwords doesn’t appear, see Troubleshooting.

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 with POST /api/v1/auth/intent.
  • @gmail.com and @googlemail.com addresses: the address and the app password are enough. The server settings are filled in for you.
  • Workspace addresses: pass imap.gmail.com and smtp.gmail.com (below).
The engine signs in to both servers before saving anything. The response is the account (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 enter imap.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:
An email with several labels is synced once per label. For example, an email in the Inbox that also has the label Clients appears twice in the API, once in each folder, with two email.new events. Both share the same message_id, so you can group them. Emails with only one label (the usual case for the Inbox) appear once.To avoid copies, users can hide labels from IMAP: Gmail Settings → Labels → Show in IMAP, unticked for labels you don’t need.

Moving, archiving and deleting

  • Moving to a folder through the API (PATCH /emails/{id} with folder) 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 get email.delete for 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 get email.update with role: "TRASH". Gmail empties the Trash after 30 days.

Sending

Emails sent through the API go out through smtp.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’s account_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