Skip to content

Example: Gmail Receive Watch

This example shows foreground Gmail receive polling.

Use mailatlas receive watch when you want a local workspace to stay current while a shell, process supervisor, launchd job, systemd user service, or MCP server process is running.

MailAtlas does not install a hidden daemon. Watch mode is a foreground process.

Authorize receive access first:

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

Use --capability send,receive only when the same local token should also support Gmail sends.

Use --max-runs while testing:

Terminal window
mailatlas receive watch \
--provider gmail \
--label INBOX \
--interval 60 \
--max-runs 2

The command prints one compact JSON object per run:

{"status":"ok","provider":"gmail","account_id":"gmail:[email protected]:INBOX","fetched_count":3,"ingested_count":2,"duplicate_count":1,"error_count":0,"document_ids":["..."],"cursor":{"history_id":"123456"},"run_id":"...","error":null}

Omit --max-runs for a foreground loop:

Terminal window
mailatlas receive watch \
--provider gmail \
--label INBOX \
--interval 60

Stop it with Ctrl-C or with the process manager that started it.

Terminal window
mailatlas receive watch \
--query 'newer_than:7d' \
--interval 120

Queries are useful when a label is too broad. Keep the query stable for a receive account so cursor and run history remain easy to interpret.

Terminal window
mailatlas receive status
mailatlas list

Use receive status to see recent run counts and errors. Use list to inspect documents created by watch mode.

  • Watch mode runs one receive pass immediately on startup.
  • --interval must be a positive integer.
  • --max-runs is useful for tests and scheduled jobs.
  • Provider errors use bounded backoff before the next pass.
  • Receive is read-only and does not mutate the Gmail mailbox.
  • Treat the workspace as private email data.