Skip to content

IMAP Receive

Use IMAP receive when messages are still in a live mailbox and you want MailAtlas to fetch selected folders into a local workspace.

If you already have .eml files or an mbox file on disk, use file ingest instead.

The canonical live-mailbox command is mailatlas receive. Use --provider imap for IMAP. Run mailatlas receive watch --provider imap when you want a foreground polling process, or run one bounded pass when you want a manual backfill or script step. MailAtlas stores per-folder IMAP cursors in SQLite so later runs can continue incrementally when possible.

You need:

  • A working MailAtlas install.
  • An IMAP host.
  • A mailbox username.
  • One credential type: password or OAuth access token.
  • One or more folder names to receive. INBOX is the default.
  • A workspace root where MailAtlas can store documents and cursor state.

MailAtlas does not persist mailbox passwords or OAuth access tokens in the workspace.

Use password auth when your provider allows IMAP passwords or app passwords.

Terminal window
export MAILATLAS_IMAP_HOST=imap.example.com
export MAILATLAS_IMAP_USERNAME=user@example.com
export MAILATLAS_IMAP_PASSWORD=app-password

Use OAuth token auth when your provider or application stack already uses OAuth.

Terminal window
export MAILATLAS_IMAP_HOST=imap.example.com
export MAILATLAS_IMAP_USERNAME=user@example.com
export MAILATLAS_IMAP_ACCESS_TOKEN=oauth-access-token

MailAtlas is OAuth-compatible, but it is not your IMAP OAuth client. The intended setup is:

  1. Your application, tool, or token broker obtains an access token.
  2. You pass the access token to MailAtlas at runtime.
  3. MailAtlas uses XOAUTH2 to authenticate the IMAP session.
  4. Your application remains responsible for login UX, consent, token refresh, and secure token storage.

Run foreground polling for the default folder:

Terminal window
mailatlas receive watch --provider imap

Run foreground polling for specific folders:

Terminal window
mailatlas receive watch \
--provider imap \
--folder INBOX \
--folder Newsletters \
--interval 60

watch runs one receive pass immediately, sleeps for the interval, then repeats until you stop it. Use --max-runs when a script needs a bounded polling loop.

Receive the default folder once:

Terminal window
mailatlas receive --provider imap

Receive specific folders once:

Terminal window
mailatlas receive \
--provider imap \
--folder INBOX \
--folder Newsletters

Command-line credential overrides are available for local tests or controlled scripts:

Terminal window
mailatlas receive --provider imap --folder INBOX --password "$MAILATLAS_IMAP_PASSWORD"
mailatlas receive --provider imap --folder INBOX --access-token "$MAILATLAS_IMAP_ACCESS_TOKEN"

receive --provider imap prints one JSON object summarizing the run, local receive account, cursor, and folder details:

{
"status": "ok",
"provider": "imap",
"account_id": "imap:[email protected]:imap.example.com:INBOX",
"fetched_count": 12,
"ingested_count": 11,
"duplicate_count": 1,
"error_count": 0,
"document_ids": ["<document-id>"],
"cursor": {
"host": "imap.example.com",
"port": 993,
"username": "[email protected]",
"folders": [
{
"folder": "INBOX",
"status": "ok",
"uidvalidity": "11",
"last_uid": 4812,
"error": null
}
]
},
"run_id": "<run-id>",
"error": null,
"details": {
"status": "ok",
"folder_count": 1,
"folders": [
{
"folder": "INBOX",
"status": "ok",
"fetched_count": 12,
"ingested_count": 11,
"duplicate_count": 1,
"document_refs": [
{
"id": "<document-id>",
"subject": "Daily market digest",
"source_kind": "imap",
"created_at": "<timestamp>"
}
],
"error": null
}
]
}
}

Use document_ids[] with mailatlas get.

Terminal window
mailatlas list
mailatlas get <document-id>
mailatlas get <document-id> --format markdown --out ./received-message

For IMAP-received documents, source_kind is imap and metadata.source.* records the mailbox folder and UID that produced the stored document.

When you receive from the same workspace root, MailAtlas uses stored IMAP cursor state to fetch only newer messages when possible.

If you point the command at a different workspace root, MailAtlas starts a fresh receive history.

When a provider reports changed UIDVALIDITY, MailAtlas starts from the beginning of the folder for that cursor because previous UIDs can no longer be treated as stable.

receive --provider imap accepts the same parser-cleaning flags as file ingest, including:

  • --strip-forwarded-headers
  • --strip-boilerplate
  • --strip-link-only-lines
  • --stop-at-footer
  • --strip-invisible-chars
  • --normalize-whitespace

Use Parser Cleaning for behavior and tradeoffs.

Use mailatlas receive --provider imap when messages are still in a live mailbox and MailAtlas should fetch them over IMAP.

Use mailatlas ingest path/to/archive.mbox when you already have a mailbox export on disk.

An mbox file is not an IMAP folder. It is a local file format.

Check that only one credential mode is active. Use either password auth or OAuth token auth.

For password auth, confirm your provider allows IMAP app passwords.

For OAuth, confirm the access token is valid, not expired, and authorized for IMAP access.

Confirm the exact folder name with your provider. Some providers use localized or nested folder names.

Duplicates can occur when messages already exist in the workspace. MailAtlas deduplicates by message_id when present and falls back to a normalized content hash.

Confirm you are using the same MAILATLAS_HOME or --root as the earlier receive run. IMAP cursor state is stored per workspace.