New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

imapflow

Package Overview
Dependencies
Maintainers
1
Versions
252
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imapflow

IMAP Client for Node

Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
2.1M
-45.06%
Maintainers
1
Weekly downloads
 
Created
Source

ImapFlow

Modern and easy-to-use IMAP client library for Node.js.

npm license

ImapFlow provides a clean, promise-based API for working with IMAP, so you don't need in-depth knowledge of the protocol. IMAP extensions are detected and handled automatically. You write the same code regardless of server capabilities, and ImapFlow adapts behind the scenes. ImapFlow is the IMAP engine that powers EmailEngine, a self-hosted email API built by the same team.

Features

  • Async/await API - all methods return Promises
  • Automatic IMAP extension handling - CONDSTORE, QRESYNC, IDLE, COMPRESS, and more
  • Message streaming - async iterators for efficient processing
  • Mailbox locking - built-in locking mechanism for safe concurrent access
  • TypeScript support - written in TypeScript, type definitions included
  • ES modules and CommonJS - import { ImapFlow } from 'imapflow' and const { ImapFlow } = require('imapflow') both work
  • Proxy support - SOCKS and HTTP CONNECT proxies
  • Gmail support - labels, raw search via X-GM-EXT-1

Installation

npm install imapflow

ImapFlow requires Node.js 20 or newer. The package ships both an ES module build and a CommonJS build with bundled type declarations, so no separate @types package is needed.

The ES module build also runs on Bun (tested against the latest release) and on Cloudflare Workers with the nodejs_compat compatibility flag. On Workers connect with implicit TLS (secure: true, usually port 993) or in cleartext: the runtime can not upgrade an already connected socket, so a STARTTLS negotiation fails with a TLS error, and it does not allow turning certificate validation off, so tls: { rejectUnauthorized: false } is rejected with ERR_OPTION_NOT_IMPLEMENTED. COMPRESS=DEFLATE, IDLE and the default pino logger work as on Node.js.

Quick Example

import { ImapFlow } from 'imapflow';
// or in CommonJS: 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 () => {
    await client.connect();

    let lock = await client.getMailboxLock('INBOX');
    try {
        // fetch latest message
        let message = await client.fetchOne(client.mailbox.exists, { source: true });
        console.log(message.source.toString());

        // list subjects for all messages
        for await (let message of client.fetch('1:*', { envelope: true })) {
            console.log(`${message.uid}: ${message.envelope.subject}`);
        }
    } finally {
        // always release the lock
        lock.release();
    }

    await client.logout();
};

main().catch(console.error);

See the Quick Start guide for more examples, including Gmail, Outlook, and Yahoo configuration.

Documentation

Full documentation is available at imapflow.com.

ImapFlow was built for EmailEngine, a self-hosted email API that turns Gmail, Microsoft 365, and IMAP accounts into REST endpoints, with managed OAuth2 and webhooks for incoming mail. If you need a production email integration rather than an IMAP client, start there.

License

Copyright (c) 2020-2025 Postal Systems OU

Licensed under the MIT license.

Keywords

imap

FAQs

Package last updated on 10 Sep 2026

Related posts