Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/puiusabin/bun-smtp/llms.txt

Use this file to discover all available pages before exploring further.

Welcome to bun-smtp

A fast SMTP/LMTP server library built natively on Bun, designed to be a drop-in replacement for smtp-server with significantly better performance.

Why bun-smtp?

bun-smtp leverages Bun’s native APIs like Bun.listen(), socket.upgradeTLS(), and Bun.CryptoHasher to deliver a high-performance SMTP server without relying on Node.js compatibility layers. If you’re already using Bun, bun-smtp provides a seamless, fully-typed experience for handling email.

Quickstart

Get up and running in minutes with a minimal SMTP server

Authentication Guide

Learn how to implement SASL authentication (PLAIN, LOGIN, CRAM-MD5, XOAUTH2)

API Reference

Explore the complete API including all options and callbacks

Examples

See real-world examples of TLS, authentication, and message handling

Key Features

Built directly on Bun’s native APIs without Node.js compatibility overhead. Uses Bun.listen() for optimal socket handling and Bun.CryptoHasher for authentication.
Same constructor options, callbacks, and event names as smtp-server. Migrate with minimal code changes while gaining significant performance improvements.
Implements the complete SMTP protocol including HELO/EHLO, MAIL FROM, RCPT TO, DATA, STARTTLS, LMTP mode, and extension commands like XCLIENT and XFORWARD.
Built-in support for PLAIN, LOGIN, CRAM-MD5, and XOAUTH2 authentication methods with configurable options for insecure auth and required authentication.
Fully typed API with comprehensive TypeScript definitions for all options, callbacks, session data, and authentication objects.

Quick Example

Here’s a minimal SMTP server that accepts all messages:
import { SMTPServer } from "bun-smtp";

const server = new SMTPServer({
  authOptional: true,
  onData(stream, session, callback) {
    async function drain() {
      const chunks: Uint8Array[] = [];
      for await (const chunk of stream) {
        chunks.push(chunk);
      }
      callback(null);
    }
    drain().catch(callback);
  },
});

await server.listen(2525);
console.log("SMTP server listening on port 2525");

System Requirements

bun-smtp requires Bun 1.2.0 or higher. Make sure you have Bun installed before getting started.
Install Bun if you haven’t already:
curl -fsSL https://bun.sh/install | bash

Community & Support

License

bun-smtp is distributed under the MIT License. See the LICENSE file for details.

Build docs developers (and LLMs) love