email-imap-smtp

Public

Secure IMAP and SMTP email tools with relative-date search, protected credentials, and opt-in send and Trash capabilities.

57 Downloads

README

Email IMAP/SMTP for LM Studio

A hardened fork of altra/email for searching and reading email over IMAP, with optional SMTP sending and move-to-Trash tools.

What changed in this fork

  • Fixes email_search failures when ImapFlow returns false instead of a UID array.
  • Uses ImapFlow's object-based search criteria instead of raw IMAP command arrays.
  • Supports validated exact and relative dates such as 2026-08-01, yesterday, 2 weeks ago, and last 3 months.
  • Prevents TypeScript builds from generating duplicate CommonJS test files.
  • Obscures password fields in LM Studio.
  • Keeps email_send and email_delete unavailable unless explicitly enabled in settings.
  • Treats email content as untrusted external data and adds prompt-injection boundaries.
  • Uses read-only mailbox access for list, search, and read operations.
  • Rejects missing UIDs, invalid date ranges, ambiguous account labels, malformed headers, and nonexistent Trash folders.
  • Limits returned body size and excludes raw HTML by default.
  • Adds deterministic unit tests, optional network integration tests, and GitHub Actions CI.

Tools

Read-only tools are always available after an account is configured:

ToolPurpose
email_accountsList accounts and exposed capabilities
email_listList recent messages from a folder
email_searchSearch by text, sender, recipient, subject, date, or unread state
email_readRead one message by UID
email_list_foldersDiscover exact mailbox folder names

Write tools are disabled by default:

ToolSetting requiredEffect
email_sendExpose email_sendSends a plain-text message over SMTP
email_deleteExpose email_deleteMoves selected UIDs to Trash; it does not permanently erase them

Enabling a write tool exposes it to the active model. Configure LM Studio to ask for tool-call approval, and inspect the final arguments before approving.

Installation

From LM Studio Hub, use Run in LM Studio. For local development:

npm install
npm run check
lms dev

npm run check runs unit tests, builds the plugin, and runs the unit tests again to detect generated-test regressions.

Configuration

Up to three accounts are supported. A slot is active when IMAP host, username, and password are all populated.

SettingTypical Gmail value
IMAP hostimap.gmail.com
IMAP port993
SMTP hostsmtp.gmail.com
SMTP port587
UsernameFull email address
PasswordProvider-issued app password

SMTP host may be left blank for a read-only account. email_send additionally requires the global plugin toggle Expose email_send.

Gmail

Enable two-step verification and create a Google app password for the plugin. Use the app password, not the normal Google account password.

Outlook and Microsoft 365

This fork currently implements username/password IMAP and SMTP authentication, not OAuth2. Microsoft tenants that disable basic authentication will not work. Do not advertise universal Microsoft 365 compatibility until OAuth2 is implemented and tested.

Other providers

Use the provider's documented IMAP/SMTP hosts, ports, and app-password requirements. Some providers disable IMAP or SMTP by default or require a paid plan.

Date search semantics

since is inclusive and before is exclusive. To search one exact day, use the next day as the upper bound:

since="2026-08-01", before="2026-08-02"

Accepted forms:

2026-08-01
today
yesterday
tomorrow
2 days ago
2 weeks ago
a month ago
last week
last 3 months

Calendar months and years are shifted as calendar units and clamp at month-end. For example, one month before March 31 becomes February 28 or 29.

Security model

This plugin has direct access to configured mailboxes. The primary risks are credential exposure, model mistakes, prompt injection in email content, accidental sending, and accidental Trash operations.

Controls included here:

  • Password inputs are protected in the UI.
  • Send and Trash tools are absent unless explicitly enabled.
  • List/search/read open mailboxes read-only.
  • Raw HTML is omitted unless requested.
  • Message bodies are truncated at a configurable character limit.
  • Header values reject CR/LF injection.
  • Email content is labeled untrusted in tool results and system instructions.

These controls reduce risk; they do not make arbitrary models trustworthy. Use a dedicated app password, keep write tools disabled when unnecessary, and review tool calls in LM Studio.

Testing

Unit tests require no mailbox credentials:

npm test

The original Ethereal SMTP tests are retained as optional network integration tests:

npm run test:integration

They require internet access and can fail due to external service availability even when the plugin code is correct.

Build

npm run build

LM Studio loads the generated root-level JavaScript files. Source tests remain under src/__tests__ and are excluded from TypeScript emission.

Publish to LM Studio Hub

Set your own Hub username or organization in manifest.json, use a unique kebab-case plugin name, then:

lms login
npm run check
lms push --write-revision

See RELEASE.md for the full checklist.

Attribution and licensing

This repository contains upstream-derived material from the public LM Studio Hub artifact altra/email and original contributions by lhzawk.

The original contributions are available under the MIT License. The upstream-derived material remains subject to the LM Studio Hub Public Content license. See LICENSE.md and NOTICE.md for details.