Skip to main content

Constructor

Create a new SMTP server instance.
SMTPServerOptions
Configuration options for the server. See Configuration for all available options.

Methods

listen()

Start the SMTP server and bind to a port.
Parameters:
number
Port number to bind to
string
default:"0.0.0.0"
Hostname or IP address to bind to
() => void
Function called when the server starts listening
Returns: this (for chaining)
The listening event is emitted after the server successfully binds to the port.

close()

Gracefully shut down the server. Active connections are allowed to finish within the closeTimeout period.
() => void
Function called when the server has fully closed
Returns: this (for chaining)
Connections still active after closeTimeout milliseconds are forcibly terminated.

updateSecureContext()

Hot-reload TLS certificates without restarting the server. New connections will use the updated certificates.
object
required

Event Methods

on()

Register an event listener.
string
required
Event name. See Events for available events.
function
required
Callback function to invoke when the event is emitted
Returns: this (for chaining)

once()

Register a one-time event listener that is automatically removed after firing once.
string
required
Event name
function
required
Callback function to invoke once
Returns: this (for chaining)

off()

Remove an event listener.
string
required
Event name
function
required
The exact listener function to remove
Returns: this (for chaining)

Properties

SMTPServerOptions
The resolved configuration options (defaults merged with constructor options)
Set<ConnectionContext>
Set of currently active connections
boolean
Whether the server is in the process of shutting down

Example