npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

smtp-imap-mcp-lib

v0.1.0

Published

MCP server providing SMTP and IMAP tools, usable via stdio or in-process

Downloads

37

Readme

smtp-imap-mcp-lib

An MCP (Model Context Protocol) server that exposes SMTP and IMAP capabilities as tools. Works both as a stdio process (e.g. with Claude Desktop) and as an in-process library that you call directly from your own TypeScript/JavaScript code.

Author: @appler1009


Features

| Tool | Description | |---|---| | smtpSendEmail | Send an email via SMTP | | smtpTestConnection | Verify SMTP server reachability and credentials | | imapTestConnection | Verify IMAP server reachability and credentials | | imapListFolders | List all mailbox folders | | imapListMessages | List messages in a folder (most recent first) | | imapGetMessage | Fetch a single message by UID (headers + body) | | imapSearchMessages | Search messages by subject, sender, date range, or read status |


Installation

npm install smtp-imap-mcp-lib
# or
pnpm add smtp-imap-mcp-lib

Credential resolution

Every tool accepts credentials through one of three mechanisms, tried in this order:

1. Inline (direct parameters)

Pass host, username, and password directly in the tool input. port and secure are optional.

{
  "host": "smtp.gmail.com",
  "port": 587,
  "secure": false,
  "username": "[email protected]",
  "password": "app-password",
  "from": "[email protected]",
  "to": "[email protected]",
  "subject": "Hello"
}

2. Named config profile (configId)

Point to a profile in a JSON credentials file. Set the file path via:

  • the SMTP_IMAP_CONFIG_FILE environment variable, or
  • the configFilePath option in CredentialResolver.

credentials.json

{
  "work-smtp": {
    "host": "smtp.company.com",
    "port": 587,
    "secure": false,
    "username": "[email protected]",
    "password": "secret"
  },
  "work-imap": {
    "host": "imap.company.com",
    "port": 993,
    "secure": true,
    "username": "[email protected]",
    "password": "secret"
  }
}

Then pass "configId": "work-smtp" instead of inline credentials.

3. Environment variables

Set these and omit credentials from the tool input entirely:

# SMTP defaults
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_SECURE=false
[email protected]
SMTP_PASSWORD=your-password

# IMAP defaults
IMAP_HOST=imap.example.com
IMAP_PORT=993
IMAP_SECURE=true
[email protected]
IMAP_PASSWORD=your-password

Usage: stdio MCP server

As a global CLI

npx smtp-imap-mcp

Claude Desktop configuration

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "smtp-imap": {
      "command": "npx",
      "args": ["smtp-imap-mcp"],
      "env": {
        "SMTP_IMAP_CONFIG_FILE": "/path/to/credentials.json"
      }
    }
  }
}

Or with inline env-var credentials:

{
  "mcpServers": {
    "smtp-imap": {
      "command": "npx",
      "args": ["smtp-imap-mcp"],
      "env": {
        "SMTP_HOST": "smtp.gmail.com",
        "SMTP_PORT": "587",
        "SMTP_SECURE": "false",
        "SMTP_USERNAME": "[email protected]",
        "SMTP_PASSWORD": "app-password",
        "IMAP_HOST": "imap.gmail.com",
        "IMAP_PORT": "993",
        "IMAP_SECURE": "true",
        "IMAP_USERNAME": "[email protected]",
        "IMAP_PASSWORD": "app-password"
      }
    }
  }
}

Usage: in-process library

Embed the MCP server in your own process

import { createMcpServer } from 'smtp-imap-mcp-lib';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = createMcpServer();
await server.connect(new StdioServerTransport());

Provide a custom CredentialResolver:

import { createMcpServer, CredentialResolver } from 'smtp-imap-mcp-lib';

const resolver = new CredentialResolver({
  config: {
    'my-smtp': { host: 'smtp.example.com', port: 587, secure: false, username: 'u', password: 'p' },
  },
});

const server = createMcpServer(resolver);

Call tool functions directly (no MCP protocol)

import { smtpSendEmail, imapListMessages, CredentialResolver } from 'smtp-imap-mcp-lib';

const resolver = new CredentialResolver({
  configFilePath: './credentials.json',
});

// Send an email
const result = await smtpSendEmail(resolver, {
  configId: 'work-smtp',
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Meeting tomorrow',
  text: 'See you at 10am.',
});
console.log(JSON.parse(result.content[0].text));
// { messageId: '<...>', accepted: ['[email protected]'], rejected: [] }

// List messages
const msgs = await imapListMessages(resolver, {
  configId: 'work-imap',
  mailbox: 'INBOX',
  limit: 10,
});
console.log(JSON.parse(msgs.content[0].text));

All exported functions

// SMTP
import { smtpSendEmail, smtpTestConnection } from 'smtp-imap-mcp-lib';

// IMAP
import {
  imapTestConnection,
  imapListFolders,
  imapListMessages,
  imapGetMessage,
  imapSearchMessages,
} from 'smtp-imap-mcp-lib';

// Infrastructure
import { CredentialResolver, createMcpServer } from 'smtp-imap-mcp-lib';

Every function returns { content: [{ type: 'text', text: string }], isError?: boolean }. On success, text is a JSON string with the result. On error, isError is true and text contains the error message.


Tool reference

smtpSendEmail

| Field | Type | Required | Description | |---|---|---|---| | from | string | ✓ | Sender address | | to | string | string[] | ✓ | Recipient(s) | | subject | string | ✓ | Subject line | | text | string | | Plain-text body | | html | string | | HTML body | | cc | string | string[] | | CC recipients | | bcc | string | string[] | | BCC recipients | | replyTo | string | | Reply-To address | | + credential fields | | | See above |

imapListMessages

| Field | Type | Default | Description | |---|---|---|---| | mailbox | string | INBOX | Folder path | | limit | number | 50 | Max messages to return (most recent first) | | + credential fields | | | |

imapGetMessage

| Field | Type | Required | Description | |---|---|---|---| | uid | number | ✓ | UID of the message | | mailbox | string | INBOX | Folder path | | + credential fields | | | |

Returns: uid, subject, from[], to[], date, flags[], source (raw RFC 2822).

imapSearchMessages

| Field | Type | Description | |---|---|---| | subject | string | Substring match on subject | | from | string | Sender address or name | | to | string | Recipient address or name | | body | string | Body text search | | since | string | ISO 8601 date — messages on or after | | before | string | ISO 8601 date — messages before | | unseen | boolean | Only unread messages | | seen | boolean | Only read messages | | limit | number | Max UIDs to return (default 50) | | + credential fields | | |


Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Type-check without building
npm run typecheck

# Run the stdio server in development (no build needed)
npm run dev

License

MIT