bun-smtp
v0.4.0
Published
A fast SMTP/LMTP server library for Bun
Maintainers
Readme
[!WARNING] STARTTLS requires a Bun canary build. Bun's server-side
socket.upgradeTLS()was blocked since bun-smtp's inception by oven-sh/bun#25044 (closed 2026-07-24). The fix has landed upstream — the architecture prerequisite in Bun 1.3.14 (oven-sh/bun#29932) plus the actualisServersupport in oven-sh/bun#32630 — but as of this writing it's only available on Bun canary builds, not yet in any stable release (latest stable is 1.3.14). On stable Bun, a STARTTLS attempt closes the connection rather than crashing the server. For production on stable Bun, use implicit TLS (port 465) or terminate TLS externally with HAProxy or stunnel; to use STARTTLS today, install Bun canary (bun upgrade --canary).
An ultrafast SMTP/LMTP server library built natively on Bun.
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);Quick Start
bun add bun-smtpFeatures
Ultrafast ⚡ - Up to 3x faster than
smtp-serveron large payloads, 54% faster on concurrent transactions. See Benchmarks.Bun-native 🚀 - Uses
Bun.listen()andBun.CryptoHasher. No Node.js compat layer. STARTTLS works viasocket.upgradeTLS()on Bun canary (oven-sh/bun#25044 is closed upstream; not yet in a stable release).Drop-in replacement 🔄 - Same constructor options, callbacks, and event names as
smtp-server. Minimal migration effort.Full SMTP support 📨 - HELO, EHLO, MAIL FROM, RCPT TO, DATA, STARTTLS, LMTP, and more.
SASL auth 🔐 - PLAIN, LOGIN, CRAM-MD5, and XOAUTH2 out of the box.
TypeScript first 🟦 - Fully typed API with strong types throughout.
Benchmarks
vs smtp-server on Node, same machine, same client:
| Scenario | bun-smtp | smtp-server | Advantage | | ------------------------------------------- | ------------ | ------------ | ----------- | | Concurrent transactions (50 connections) | 43,650 msg/s | 28,257 msg/s | +54.5% | | Large payloads (10 connections, 1MB bodies) | 1,669 MB/s | 573 MB/s | +191.1% |
Methodology and full results: bench/RESULTS.md. Run it yourself: bun run bench.
Documentation
Contributing
Contributions welcome.
- Open an issue to propose a feature or report a bug.
- Open a pull request to fix a bug or improve docs.
Authors
Sabin Puiu https://github.com/puiusabin
License
Distributed under the MIT License. See LICENSE for more information.
