How to Use a Local LLM with Your Email
On this page
A local large language model (LLM) is an AI model that runs on your computer and generates answers there. To ask it questions about email, it needs access to message text. One way to provide that text is to copy messages into a local archive, then use software called a model interface to read those files.
mailmd prepares the archive by copying email into Markdown files, a plain-text format, on your computer, one file per message. mailmd does not run a model or search your mail. You use a separate model interface to work with the files. Keeping the files on your computer does not keep model processing local; the interface must also use a model running on your computer.
Prepare your email with mailmd #
mailmd is a free, open-source command-line tool that copies email into a folder on your computer. You use a command-line tool by typing commands in a terminal. mailmd reads messages without marking them as read, moving them, deleting them, or sending mail. Its logins request read access, and the tool has no mailmd server or telemetry.
Install mailmd on Linux, macOS, or Windows in Git Bash, then connect your account and sync:
curl -fsSL https://raw.githubusercontent.com/vincentsch/mailmd/main/install.sh | sh
mailmd connect imap --email you@example.com
mailmd syncThe IMAP command connects to mail services that support IMAP, a standard way for mail software to access messages. Some providers require an app password, and mailmd indicates when one is needed. For Gmail, you can use IMAP with an app password or connect through the Gmail API. For Outlook.com and Microsoft 365, use Microsoft Graph, Microsoft’s service for accessing account data. Those API connections require you to register an OAuth app, which authorizes access to your account, in Google Cloud or Microsoft Entra. The commands are mailmd connect gmail --client-secret client_secret.json and mailmd connect outlook --client-id <id>.
After syncing, mail is stored under ~/mail/<account>. Each message becomes a Markdown file with its headers, readable message text, and links or tables preserved. Attachments sit beside the message. Use --keep-raw to also save the original .eml file. By default, spam and trash are excluded. With Gmail over IMAP, mailmd syncs All Mail, which includes archived messages.
Run mailmd sync again to add new messages and update whether messages are read or starred. mailmd never deletes files from the archive. If a message disappears from the mailbox, its archived file remains and is marked as deleted on the server. You can use --folder, --exclude, and --since to choose what mail to copy. See the mailmd project instructions for current setup details.
Connect the archive to a local model #
After mailmd creates the archive, use a model interface that can read local Markdown files. Check that the selected model runs on your computer. Ask it to summarize a message, list the sender’s request, or draft a reply for review. Start with a small selection of messages and check every answer against the original.
A local archive alone does not make model processing local. For example, coding agents can read the files in a mail folder, but the agent sends what it reads to its model provider. In that setup, the agent sends the message text to its provider instead of processing it with a model on your computer. Check the model interface’s settings and connection before sharing sensitive messages.
mailmd has no search engine of its own. You can search the files with an editor, a note-taking app, or command-line tools such as rg and grep. To filter messages with a script, use index.jsonl, which lists them in a format scripts can read. A model interface still needs a way to find and open relevant files; the archive by itself does not provide automatic mailbox-wide question answering.
Protect the archive and review model answers #
Email can contain sensitive personal or business information. The archive is stored locally, but mailmd’s saved logins are outside the archive, unencrypted, and readable only by your user account. When deciding who can access your computer and what to back up, account for both the archive and the stored logins.
A local model can also misread a message or follow malicious instructions embedded in its text. Research on email agents documents prompt-injection attacks, in which a message tries to influence an AI system’s instructions or actions. LLMail-Inject reports attacks against the email-agent systems it evaluated. Those results do not predict how a specific local model will perform. For safer use, ask for summaries and draft replies, then verify names, dates, commitments, and cited details before acting. Do not give an AI control over sending or deleting mail.
Free and open source
Try mailmd
mailmd is a free command-line tool that copies your email into Markdown files on your computer, one file per message. It works with any IMAP mailbox, and with Gmail and Outlook through their own APIs.
Install
$ curl -fsSL https://raw.githubusercontent.com/vincentsch/mailmd/main/install.sh | sh
Set it up with your coding agent
Set up mailmd so you can read my email. Use https://github.com/vincentsch/mailmd: read its AGENTS.md and follow the steps. Connect my mailbox and run the first sync. Then show me where the files are.