Gmail, iCloud and IMAP mail for Claude Code
chainmail connects Claude Code to Gmail, Google Workspace, iCloud and Hostinger accounts through presets, and to other mail servers over IMAP and SMTP. Its daemon logs in to each account and keeps the password or token in a vault that no call reads back.
Providers chainmail supports
Each account is an [accounts.<name>] table in the daemon's config, and its provider names a preset. The preset sets the servers and the ways the account can log in.
gmailusesimap.gmail.comandsmtp.gmail.com, and logs in with an app password or OAuth2.google-workspaceuses the same servers, and logs in with OAuth2.icloudusesimap.mail.me.comandsmtp.mail.me.com, and logs in with an app-specific password.hostingerusesimap.hostinger.comandsmtp.hostinger.com, and logs in with the mailbox password.customuses the IMAP and SMTP servers you name. It logs in with a password, or with OAuth2 through a client that has an OpenID Connect issuer.
chainmail bootstrap finds the provider from the address. gmail.com and googlemail.com are Gmail, and icloud.com, me.com and mac.com are iCloud. For any other domain, bootstrap looks up the MX records, matches Google's and Hostinger's mail servers, and asks you to confirm. --provider names the preset instead.
Gmail with an app password
Turn on 2-Step Verification for the Google account, then create an app password at myaccount.google.com/apppasswords. Run bootstrap with your Gmail address. Before it asks for the password, it prints the page where you make one.
chainmail bootstrap [email protected]An account with an app password reads and sends mail. The Google Calendar API takes no password, so chainmail reads no calendar for the account. It can still answer an invite that arrives by mail, with a reply by email.
Gmail and Google Workspace with OAuth2
Both Google presets can log in with OAuth2 and the scope https://mail.google.com/. You register your own OAuth client of type Desktop app with Google once. A Workspace account needs a Google Cloud project with an Internal audience. A personal Gmail account needs a separate project with an External audience, published so that its refresh tokens do not expire after 7 days.
For Google Workspace, pass the client ID to bootstrap. It asks for the client secret from the JSON file that Google gave you, then runs the login on your terminal.
chainmail bootstrap [email protected] --oauth-client-id 1234.apps.googleusercontent.comThe login prints a consent URL. Open it in any browser, on any machine, and approve. The browser is then sent to http://127.0.0.1:53682/ and fails to load the page, which is expected. Copy the full URL from the address bar and paste it into the terminal.
A personal Gmail account that should use OAuth2 is set up by hand in the config, then logged in with chainmail auth login. Google OAuth2 in the manual lists every step in the Google Cloud console.
A Google account that logs in with OAuth2 also syncs its calendars through the Google Calendar API. That needs the Calendar API enabled in the project and three more scopes, which Calendars lists.
iCloud
Create an app-specific password at account.apple.com, under Sign-In and Security. Run bootstrap with your iCloud address, and enter that password when it asks.
chainmail bootstrap [email protected]chainmail logs in with the full address. If the IMAP server rejects that, set username in the account's table to the part of the address before the @.
Hostinger
Use the mailbox password from hPanel. Bootstrap recognizes a Hostinger domain from its MX records. Hostinger keeps folders under INBOX., so write folder names in the config as chainmail folders prints them, such as INBOX.Archive.
Other IMAP and SMTP servers
The custom preset has no servers of its own, so the account names both. Bootstrap does not set up a custom account. Add its table to /etc/chainmail/config.toml with sudo:
[accounts.lab]
provider = "custom"
address = "[email protected]"
username = "me"
imap = { host = "mail.example.net", port = 993 }
smtp = { host = "mail.example.net", port = 587, security = "starttls" }host and port are required. security is tls, the default, or starttls. username is the login name, and defaults to the address.
Restart the daemon so it reads the new account, then store the password in the vault. On macOS, restart it with sudo launchctl kickstart -k system/sh.chainmail.daemon in place of the first line.
sudo systemctl restart chainmail
chainmail secret set accounts/labA custom server with CalDAV calendars can sync them too, as Calendars describes.
Check every account
chainmail accounts list --output table
chainmail accounts test lab --output tableaccounts test logs in to the account's IMAP server, then its SMTP server, and reports each check. It exits 5 when a server rejects the credentials.
The daemon does not retry rejected credentials, because providers lock out accounts that keep failing. It marks the account as needing you, and calls for it fail with AUTH_REQUIRED and a hint that names the fix. For a rejected password, the fix is chainmail secret set accounts/<account>.
Connect Claude Code
Once an account passes its test, register chainmail with Claude Code:
claude mcp add --scope user chainmail -- "$(command -v chainmail)" mcpConnect Claude Code to your email covers the install and the first requests. Let Claude send email safely explains what happens to a send off your allowlist, and the features page lists the tools.