Back to browse
GitHub Repository

SMTP and LMTP server library for Bun

7 starsTypeScript

I rewrote SMTP-server for Bun without touching node:net

by puiusabin·Mar 1, 2026·1 point·0 comments

AI Analysis

●●SolidShip It

Bun-native SMTP avoids Node.js overhead; drop-in replacement for smtp-server with faster socket handling.

Strengths
  • Leverages Bun.listen() and socket.upgradeTLS() for native TCP and TLS without Node compat tax.
  • SASL auth (PLAIN, LOGIN, CRAM-MD5, XOAUTH2) and full SMTP/LMTP support out of box.
  • Serialized async drain loop prevents deadlocks and preserves command ordering without complex state machines.
Weaknesses
  • No benchmarks or performance claims substantiated—'faster than Node.js' is assumed, not proven.
  • Minimal documentation and early-stage API stability unclear; smtp-server is a 10-year-old standard.
Target Audience

Bun developers building email infrastructure; mail server and transactional email service builders.

Similar To

nodemailer (smtp-server) · Haraka · Postfix (as a library)

Post Description

Hi HN, I'm the developer behind bun-smtp.

I've been using Bun recently and realized that while I could use existing Node.js libraries like the smtp-server package, I wanted an SMTP server specifically tailored to take advantage of Bun's native APIs and performance without the extra Node-compatibility overhead.

How it works under the hood: It's built on Bun.listen() for raw TCP server sockets, with all SMTP state transitions and line parsing handled in a serialized async drain loop that keeps command ordering intact without deadlocks. STARTTLS upgrades happen in-place via socket.upgradeTLS(), and the email body is delivered to the onData handler as a Web ReadableStream rather than a Node.js stream.

I built this mostly to solve my own itch, but I'd love for the community to tear into the code and tell me what I did wrong or how I can improve the TCP/buffer handling. Happy to answer any questions!

Similar Projects