Which should you choose: Gmail API or IMAP?
For a new Gmail-only agent, start with Gmail API. Its narrower OAuth scopes let you separate reading from sending at Google's authorization boundary. For an application spanning several providers, consider IMAP if reusing a shared mail protocol matters more than a Gmail-specific implementation.
Gmail API is Google's application interface for Gmail. IMAP is a mailbox-access protocol; sending uses a separate path, typically SMTP. OAuth is an authorization mechanism, not an alternative to IMAP: Gmail supports OAuth for IMAP and SMTP.
Mailera adds another layer. Your agent uses its REST API or MCP, while Mailera connects to Gmail through an app password and IMAP/SMTP. That does not make the underlying connection Gmail API OAuth.

This is an access-design decision, not a full setup tutorial. For a broader provider comparison, see connecting existing email providers to agents.
How do Gmail API and IMAP compare for agent access?
| Decision | Direct Gmail API | Direct Gmail IMAP |
|---|---|---|
| Provider coverage | Gmail-specific implementation | Shared protocol useful across providers; authentication still varies |
| Authentication | Google OAuth with task-specific scopes | Gmail supports OAuth; eligible accounts can use app passwords |
| Permission granularity | Separate read-only, metadata, and send scopes | Standard Gmail protocol OAuth uses the broad https://mail.google.com/ scope |
| Labels and threads | Gmail-specific message model | Labels appear as folders; Gmail extensions expose labels and thread IDs |
| Search | Include search requirements when selecting scopes | X-GM-RAW exposes Gmail search syntax |
| Synchronization | Initial retrieval, incremental history, optional Pub/Sub notifications | Plan connection recovery, folder tracking, and update checks |
| Sending | Available with an appropriate send scope | IMAP does not send; configure SMTP separately |
| Operational work | OAuth deployment, history recovery, quotas, watch renewal | Provider authentication, connection handling, identifiers, folder mapping |
Do not assume IMAP loses Gmail's labels. Google's IMAP extensions expose X-GM-LABELS, the cross-folder message identifier X-GM-MSGID, and the thread identifier X-GM-THRID.
Those extensions also explain why a generic folder view needs care. One Gmail message can appear under multiple labels. Before treating two folder entries as duplicate emails, inspect their identifiers.
Base your choice on these requirements, not a blanket claim about speed. Measure retrieval volume and synchronization behavior for your workload, including the work needed after a connection or synchronization gap.
What changes when you implement Gmail API directly?
Start with the permission boundary
An agent that summarizes messages needs different authority from one that sends replies. Select permissions before implementing tools.
| Agent task | Scope to consider | Boundary |
|---|---|---|
| Read message bodies | gmail.readonly | Views messages and settings; classified as restricted |
| Inspect labels and headers only | gmail.metadata | Does not expose message bodies |
| Send approved messages | gmail.send | Sends on the user's behalf; classified as sensitive |
These are shortened scope names; use Google's exact scope values in your OAuth configuration. If the agent must change mailbox state, review the appropriate modification permissions separately rather than assuming read access covers changes.
Google's Gmail API scope guidance describes restricted-scope verification requirements and a security assessment requirement when restricted-scope data is stored on or transmitted through servers. Review how those requirements apply to your deployment before choosing the consent flow and storage architecture.
The distinction matters even if you prefer IMAP. Google's protocol OAuth guidance recommends Gmail API's more granular scopes when an application does not need the full mail scope.
Build synchronization separately from notifications
A mailbox integration needs initial synchronization, incremental updates, and recovery:
- Initial synchronization: retrieve message IDs with
messages.list, then retrieve individual messages withmessages.get. - Incremental synchronization: retain a history position and use
history.listwithstartHistoryIdto retrieve newer changes. - Recovery: if the history position is out of range, Gmail returns HTTP
404; perform a full synchronization.
Google's synchronization guide covers these paths. Make recovery part of the implementation, not an exception handled by silently skipping changes.
Gmail API push notifications use Cloud Pub/Sub. Their decoded payload contains an email address and a new history ID, not the message body. Your application must follow up to retrieve changes and content.
A mailbox watch must be renewed at least every seven days. Notifications can also be delayed or dropped, so keep a recovery path independent of individual notifications.
Separate API pricing from system cost
Google's usage limits and pricing documentation states that standard Gmail API use is available at no additional cost. Requests still consume quota units, with consumption varying by method and query parameters.
Estimate application hosting, storage, and the supporting notification infrastructure separately from API costs. Check the current pricing page when estimating costs rather than treating quota availability as a promise of unlimited free operation.
When is IMAP the more practical choice?
IMAP is worth considering when your application already has a mail client implementation, or when Gmail is one of several providers you must support. You can reuse the protocol-based design, but still need to account for each provider's authentication and behavior.
Plan for reconnects and synchronization after interruptions. Decide how your client tracks folder membership and message identity, and how it checks for changes. For Gmail, use its extensions where their semantics matter instead of reducing every operation to a generic folder abstraction.
Gmail IMAP OAuth and Gmail app passwords are different authentication choices. The standard protocol OAuth scope is broad; an app password is not a substitute for a read-only Google OAuth scope.
Google recommends “Sign in with Google” when an application offers it. Its app-password guidance requires 2-Step Verification and lists possible availability restrictions, including security-key-only configurations, organizational accounts, and Advanced Protection. Check eligibility and administrator policy without weakening account security to make a connector work.
Where does Mailera fit?
Mailera lets the agent use REST or MCP without implementing Gmail's protocol connection itself. The Gmail connection uses an app password for incoming IMAP access and SMTP for sending. The Gmail provider guide covers that connection path.
There are two authorization boundaries: the Google credential connecting the mailbox, and the Mailera key authorizing the agent. A read-only Mailera key restricts agent actions through Mailera. It does not turn the underlying app password into a read-only Google credential.
Use a mailbox you own for this validation:
- As an Admin or Leader, open Mailboxes → Add mailbox. In One mailbox, enter the Email address, check the detected provider, and select Continue.
- Review How to get an app password and What you'll need against Google's guidance. For an eligible account, enter the app password in Password, not your normal Google sign-in password. Choose a Mailbox group, then select Test & connect. The connection test does not send an email.
- Open Settings → API key → Create key. Set Mailbox scope to the intended group and select only Read. Store the key securely when it appears; it is shown only once.
- Confirm access with
list_mailboxesandlist_messagesthrough MCP, or the REST requests below. Keep addresses and message content out of shared logs and screenshots.

For MCP clients, the key dialog offers Copy MCP config for Claude, Cursor, or VS Code. See the Mailera MCP interface for that route, or the developer overview for REST.
With your key stored in $MAILERA_API_KEY, list the Gmail mailboxes visible to it:
curl --fail-with-body \
-H "Authorization: Bearer $MAILERA_API_KEY" \
'https://mailera.app/api/public/v1/mailboxes?provider=gmail&limit=1'Set $MAILBOX_ID to the intended mailbox's id from data, then request an Inbox message:
curl --fail-with-body \
-H "Authorization: Bearer $MAILERA_API_KEY" \
"https://mailera.app/api/public/v1/mailboxes/$MAILBOX_ID/messages?folder=inbox&limit=1"Inspect data and next_cursor; an empty message list is not a message-body response. To retrieve content, use get_message or GET /mailboxes/{id}/messages/{msgId}, both requiring read.

What commonly goes wrong?
| Symptom | Likely cause | Next check |
|---|---|---|
| App-password option is missing | Account security configuration or organization policy | Review Google's eligibility guidance and ask the administrator; do not relax security controls |
| Authentication fails | Incorrect or revoked credential, or policy restriction | Confirm the credential type and account policy; changing a Google Account password revokes its app passwords |
| Messages look duplicated | One message appears through several label/folder views | Inspect mapping and X-GM-MSGID before deduplicating |
| Mail appears late | Connection or synchronization state needs attention | Inspect sync timestamps and whether the mailbox is idle or sleeping |
| Reading works but sending fails | Agent lacks send permission, or SMTP setup failed | Check the agent permission separately from the outgoing connection |
Incremental Gmail API sync returns 404 | Stored history position is out of range | Perform a full synchronization |
For Gmail, Mailera's GET /mailboxes/{id}/status reflects the latest synchronization. It is not an independent live credential test.
If outgoing connection testing fails, Mailera offers Save as receive-only. That is distinct from restricting the agent key to Read; sending through Mailera requires the send permission.
How do you keep an email-reading agent safe?
Treat message bodies, attachments, and quoted text as untrusted input. An email asking the agent to ignore its rules, reveal a credential, or execute a tool is still email content, not authorization.
Start with a group-scoped, read-only key. Keep provider credentials and Mailera keys out of prompts, message content, screenshots, and logs. Require user confirmation before sending or forwarding; an incoming message must not authorize its own reply or tool execution.
Keep revocation procedures separate. Revoking the Mailera key stops that agent's API access immediately, but does not revoke the Google app password. Review both access paths when removing an integration. See the Mailera security overview when reviewing access.
What are Mailera's limits here?
Mailera connects existing mailboxes; it does not create Gmail accounts or email addresses. It cannot make app passwords available when Google settings or administrator policy disallow them.
Mailera does not promise immediate delivery in every state. Background checks vary with mailbox activity, and inactive mailboxes can sleep and wake on use. If Google-level read-only authorization is a requirement, choose direct Gmail API with an appropriate OAuth scope rather than relying on a Mailera key to narrow the underlying app password.
Connect your first mailbox in 2 minutes
Add an Outlook, Gmail or IMAP mailbox and read email messages in the app or via the API.
Connect mailbox








