Skip to content

Example: Gmail Receive

This example shows the local Gmail receive path.

Use it when you want MailAtlas to fetch Gmail messages with a read-only OAuth token and store them as ordinary MailAtlas documents.

Start with a separate workspace when testing against a real mailbox:

Terminal window
export MAILATLAS_HOME="$PWD/.mailatlas-gmail-test"

Create a Google OAuth desktop client with the Gmail API enabled, then run:

Terminal window
python -m pip install "mailatlas[keychain]"
mailatlas auth gmail \
--client-id "$MAILATLAS_GMAIL_CLIENT_ID" \
--client-secret "$MAILATLAS_GMAIL_CLIENT_SECRET" \
--capability receive

Check that the local token has receive capability:

Terminal window
mailatlas auth status gmail

The status output should include receive in capabilities. It should not print access tokens, refresh tokens, client secrets, or authorization codes.

Terminal window
mailatlas receive \
--provider gmail \
--label INBOX \
--limit 10

The command prints JSON with counts, document IDs, cursor data, and a run ID.

Expected statuses:

StatusMeaning
okReceive completed. New documents may or may not have been ingested.
duplicateAll fetched messages already existed in the workspace.
not_configuredGmail auth or required config is missing.
cursor_reset_requiredGmail rejected the stored history cursor. Run an explicit full sync.
partialAt least one fetched message failed, but some messages were ingested or skipped as duplicates.
errorProvider or storage work failed before useful progress.
Terminal window
mailatlas list
mailatlas get <document-id>

Received Gmail documents use the same local storage layout as file ingest and IMAP receive. Raw messages go under raw/; HTML and assets are stored when present.

Terminal window
mailatlas receive status

Status output includes:

  • configured receive accounts
  • Gmail cursor state
  • recent receive runs
  • the most recent error when one exists

If Gmail reports that the stored history cursor is invalid, run an explicit full sync:

Terminal window
mailatlas receive \
--provider gmail \
--label INBOX \
--limit 50 \
--full-sync

Full sync may return duplicates if messages are already stored. That is expected.

Remove local Gmail auth:

Terminal window
mailatlas auth logout gmail

Remove the test workspace when you no longer need it:

Terminal window
rm -rf "$MAILATLAS_HOME"