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

  • Posted 3 hours ago by puiusabin
  • 1 points
https://github.com/puiusabin/bun-smtp
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!

0 comments