Skip to content

Configuration ​

Pass options to the SMTPServer constructor:

ts
import { SMTPServer } from "bun-smtp";

const server = new SMTPServer({
  // options here
});

Connection ​

OptionTypeDefaultDescription
securebooleanfalseStart in implicit TLS mode (port 465 style). When false, STARTTLS is offered instead.
needsUpgradebooleanfalseReject AUTH and MAIL until the client completes STARTTLS.
namestringsystem hostnameServer hostname included in the 220 greeting and EHLO response.
bannerstring""Extra text appended to the 220 greeting line.
lmtpbooleanfalseUse LMTP instead of SMTP. Clients open with LHLO and onData may return per-recipient responses.
heloResponsestring"%s Nice to meet you, %s"Format string for the HELO/EHLO response. First %s is the server name, second is the client hostname.

Authentication ​

OptionTypeDefaultDescription
authMethodsstring[]["PLAIN", "LOGIN"]SASL methods advertised in EHLO. Supported values: "PLAIN", "LOGIN", "CRAM-MD5", "XOAUTH2".
authOptionalbooleanfalseAllow clients to skip AUTH entirely.
allowInsecureAuthbooleanfalseAllow AUTH over a plain (non-TLS) connection.
authRequiredMessagestring—Custom error message for the 530 response when auth is required.

Capability flags ​

These options hide extensions from the EHLO response. The extension still works — it is just not advertised.

OptionTypeDefaultDescription
hideSTARTTLSbooleanfalseHide STARTTLS from EHLO.
hideSizebooleanfalseHide the SIZE extension.
hidePIPELININGbooleanfalseHide PIPELINING.
hideDSNbooleanfalseHide DSN (Delivery Status Notification).
hideENHANCEDSTATUSCODESbooleanfalseHide ENHANCEDSTATUSCODES.
hideREQUIRETLSbooleanfalseHide REQUIRETLS.
hide8BITMIMEbooleanfalseHide 8BITMIME.
hideSMTPUTF8booleanfalseHide SMTPUTF8.
disabledCommandsstring[][]Block specific SMTP commands entirely (e.g. ["AUTH", "STARTTLS"]).

Limits ​

OptionTypeDefaultDescription
sizenumber—Maximum message size in bytes. Advertised via the SIZE extension. The onData stream's sizeExceeded flag is set when the limit is hit.
maxClientsnumber—Maximum number of simultaneous connections. New connections are rejected with 421 when the limit is reached.
socketTimeoutnumber60000Milliseconds of inactivity before an idle connection is closed.
closeTimeoutnumber30000Milliseconds to wait for connections to drain during server.close(). Connections still open after this are forcibly terminated.
maxAllowedUnauthenticatedCommandsnumber | false10Maximum commands allowed before authentication. Set to false to disable the limit.

Proxy / X-headers ​

OptionTypeDefaultDescription
useXClientbooleanfalseTrust Postfix XCLIENT headers. When enabled, session.xClient is populated.
useXForwardbooleanfalseTrust Postfix XFORWARD headers. When enabled, session.xForward is populated.
useProxyboolean | string[]falseParse HAProxy PROXY protocol header. Pass an array of trusted proxy IP addresses to restrict which proxies are trusted.

DNS ​

OptionTypeDefaultDescription
disableReverseLookupbooleanfalseSkip reverse DNS lookup on new connections. When false, session.clientHostname is resolved from the client's IP.
resolverobject—Custom DNS resolver. Must implement reverse(ip, callback) with the same signature as dns.reverse.

TLS ​

All standard TLS options. See TLS & STARTTLS for usage examples.

OptionTypeDescription
keystring | BufferPrivate key (PEM)
certstring | BufferCertificate (PEM)
castring | Buffer | ArrayCA bundle for client cert verification
requestCertbooleanRequest a client certificate during TLS handshake
rejectUnauthorizedbooleanReject clients with invalid or unverifiable certificates
minVersionstringMinimum TLS version string (e.g. "TLSv1.2")
maxVersionstringMaximum TLS version string
sniOptionsRecord<string, TLSOptions> | Map<string, TLSOptions>Per-hostname TLS configuration for SNI

Callbacks ​

All lifecycle callbacks can be set as constructor options:

OptionTypeDescription
onConnectOnConnectCallbackCalled on new connection
onSecureOnSecureCallbackCalled after TLS handshake
onAuthOnAuthCallbackCalled on AUTH attempt
onMailFromOnMailFromCallbackCalled on MAIL FROM
onRcptToOnRcptToCallbackCalled on RCPT TO
onDataOnDataCallbackCalled when DATA transfer begins
onCloseOnCloseCallbackCalled when connection closes

See Callbacks for full signatures and examples.

Released under the MIT License.