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.
Overview
bun-smtp is designed as a drop-in replacement for the smtp-server npm package. Most servers can migrate by simply changing the import and updating theonData callback to work with Web Streams.
bun-smtp maintains API compatibility with smtp-server to make migration seamless. All constructor options, callback signatures, and session properties remain the same.
Installation
Import Statement
Key Differences
1. onData Stream Type
This is the primary change required when migrating. smtp-server passes a Node.jsReadable stream, while bun-smtp passes a Web ReadableStream<Uint8Array>.
- Before (smtp-server)
- After (bun-smtp)
Discarding the Stream
To discard the message body without reading it:Stream Properties
Both implementations providebyteLength and sizeExceeded properties:
stream.byteLengthis set after the stream closesstream.sizeExceededbecomestruewhen the message exceedsoptions.size
2. Logger Option Removed
smtp-server accepts alogger option (bunyan-compatible). bun-smtp does not support this option.
3. onSecure Socket Type
Thesocket argument in onSecure is a Bun Socket, not a Node.js tls.TLSSocket. TLS details are available on session.tlsOptions.
What Stays the Same
Everything else is a direct drop-in replacement:Callbacks
All callback signatures remain unchanged:
onConnect(session, callback)onAuth(auth, session, callback)onMailFrom(address, session, callback)onRcptTo(address, session, callback)onData(stream, session, callback)— only the stream type changesonClose(session)
Auth Objects
Auth object shapes for all methods are identical:
- PLAIN/LOGIN:
{ method, username, password } - CRAM-MD5:
{ method, username, challenge, challengeResponse, validatePassword() } - XOAUTH2:
{ method, username, accessToken }
TLS Options
All TLS options are identical:
key,cert,casniOptionsrequestCert,rejectUnauthorizedminVersion,maxVersion
Migration Checklist
Remove logger option
If you’re using the
logger option, remove it and add logging to individual callbacks.Complete Migration Example
- Before (smtp-server)
- After (bun-smtp)
Performance Benefits
By switching to bun-smtp, you get:Faster Startup
Bun’s fast runtime means your server starts instantly, perfect for serverless deployments.
Lower Memory
Native Web Streams reduce memory overhead compared to Node.js streams.
Built-in TypeScript
No need for
@types packages — everything is fully typed out of the box.Modern APIs
Web-standard APIs make your code more portable and future-proof.
Troubleshooting
Error: stream.on is not a function
Error: stream.on is not a function
This means you’re trying to use Node.js stream methods on a Web ReadableStream. Update your
onData callback to use for await...of instead of .on() event listeners.Logger option not recognized
Logger option not recognized
bun-smtp doesn’t support the
logger option. Remove it from your configuration and add logging directly in your callbacks:TLS socket methods undefined
TLS socket methods undefined
In
onSecure, the socket is a Bun Socket, not a Node.js TLS socket. Use session.tlsOptions instead:Need Help?
If you encounter issues during migration:- Check the API Reference for detailed documentation
- Review the source code for implementation details
- Open an issue on GitHub if you find a compatibility problem