Skip to main content

ImapFlow

ImapFlow is a modern and easy-to-use IMAP client library for Node.js. The focus for ImapFlow is to provide an easy-to-use API over IMAP without requiring in-depth knowledge of the IMAP protocol.

Install with npm
npm install imapflow

Key Features

  • Modern async/await API - All methods return Promises for easy async handling
  • Automatic extension handling - IMAP extensions are handled automatically in the background
  • Message streaming - Efficient handling of large mailboxes with async iterators
  • TypeScript support - Full TypeScript type definitions included
  • Comprehensive IMAP support - Supports all major IMAP operations and extensions
  • Mailbox locking - Built-in locking mechanism for safe concurrent mailbox access
  • Proxy support - SOCKS and HTTP CONNECT proxy support for secure connections
  • Gmail support - Gmail-specific extensions including labels and raw search
Looking for a complete email gateway solution?

EmailEngine is a self-hosted email gateway that provides REST API access to IMAP and SMTP accounts, webhooks for mailbox changes, and advanced features like OAuth2, delayed delivery, open and click tracking, bounce detection, and more.

Supported IMAP Extensions

ImapFlow implements RFC 3501 (IMAP4rev1) and automatically detects and uses the following IMAP extensions when available:

ExtensionRFCDescription
IDLERFC 2177Real-time notifications without polling
CONDSTORERFC 7162Efficient change tracking with modification sequences
QRESYNCRFC 7162Quick mailbox resynchronization
UIDPLUSRFC 4315Enhanced UID operations with response data
MOVERFC 6851Atomic message move operation
IDRFC 2971Client/server identification
NAMESPACERFC 2342Mailbox namespace information
COMPRESS=DEFLATERFC 4978Connection compression
UTF8=ACCEPTRFC 6855UTF-8 mailbox names and headers
BINARYRFC 3516Binary content transfer
SPECIAL-USERFC 6154Standard mailbox roles (Sent, Trash, etc.)
X-GM-EXT-1GoogleGmail-specific features (labels, search)
OBJECTIDRFC 8474Unique object identifiers
QUOTARFC 9208Mailbox storage quota

Quick Example

Basic usage example
const { ImapFlow } = require('imapflow');

const client = new ImapFlow({
host: 'imap.example.com',
port: 993,
secure: true,
auth: {
user: 'user@example.com',
pass: 'password'
}
});

const main = async () => {
// Connect and authenticate
await client.connect();

// Select a mailbox
let lock = await client.getMailboxLock('INBOX');
try {
// Fetch latest message
let message = await client.fetchOne('*', {
envelope: true,
source: true
});
console.log(message.envelope.subject);
} finally {
lock.release();
}

// Logout
await client.logout();
};

main().catch(console.error);

Why ImapFlow?

Managing an IMAP connection can be complex, but if you're looking for an easy way to integrate email accounts, ImapFlow provides a clean, promise-based API that abstracts away the complexity of the IMAP protocol.

For production email integration needs, ImapFlow was built for EmailEngine Email API, a self-hosted software that converts IMAP accounts into easy-to-use REST interfaces.

What's Next?