Skip to content

Session & Envelope

Every callback receives a session object representing the current connection state.

SMTPSession

FieldTypeDescription
idstringUnique connection identifier
securebooleantrue if the connection is currently using TLS
servernamestring | undefinedSNI hostname from the TLS handshake
localAddressstringServer IP address
localPortnumberServer port
remoteAddressstringClient IP address
remotePortnumberClient port
clientHostnamestringReverse-DNS hostname of the client ("[remoteAddress]" if lookup fails or is disabled)
hostNameAppearsAsstringHostname the client claimed in HELO/EHLO
openingCommandstringThe first command the client sent: "HELO", "EHLO", or "LHLO"
transmissionTypestringSMTP transmission type string, e.g. "ESMTPSA"
tlsOptionsTLSCipherInfo | falseCipher info after TLS is established, false before
userunknownValue passed as user in a successful onAuth response
transactionnumberNumber of completed mail transactions on this connection
envelopeSMTPEnvelopeCurrent mail envelope
xClientMap<string, string | false>XCLIENT header values (when useXClient: true)
xForwardMap<string, string | false>XFORWARD header values (when useXForward: true)

TLSCipherInfo

FieldTypeDescription
namestringOpenSSL cipher name
standardNamestring | undefinedIANA cipher name
versionstring | undefinedTLS protocol version

SMTPEnvelope

Available as session.envelope. Populated progressively as the client sends MAIL FROM and RCPT TO commands.

FieldTypeDescription
mailFromSMTPAddress | falseSender address from MAIL FROM, or false before MAIL FROM is received
rcptToSMTPAddress[]Accepted recipient addresses from RCPT TO
bodyType"7bit" | "8bitmime"Body encoding declared by the client
smtpUtf8booleantrue if the client declared SMTPUTF8
requireTLSbooleantrue if the client sent REQUIRETLS
dsnDSNEnvelope | undefinedDSN envelope parameters

DSNEnvelope

FieldTypeDescription
ret"FULL" | "HDRS" | nullReturn type requested by the client
envidstring | nullEnvelope identifier

SMTPAddress

Returned by onMailFrom and onRcptTo, and stored in session.envelope.

FieldTypeDescription
addressstringThe email address
argsSMTPAddressArgs | falseESMTP parameters from the command, or false if none
dsnDSNRcpt | undefinedPer-recipient DSN parameters

SMTPAddressArgs

ESMTP parameters parsed from the MAIL FROM or RCPT TO command:

FieldTypeDescription
SIZEstring | undefinedDeclared message size in bytes
BODYstring | undefinedBody type: "7BIT" or "8BITMIME"
SMTPUTF8true | undefinedUTF-8 support flag
REQUIRETLStrue | undefinedTLS-required flag (RFC 8689)
RETstring | undefinedDSN return type
ENVIDstring | undefinedDSN envelope ID
NOTIFYstring | undefinedDSN notification conditions
ORCPTstring | undefinedDSN original recipient

Any unrecognized ESMTP parameter is also available as a string or true on the args object.

DSNRcpt

FieldTypeDescription
notifystring[] | undefinedDSN notification conditions (e.g. ["SUCCESS", "FAILURE"])
orcptstring | undefinedOriginal recipient address

Example

ts
const server = new SMTPServer({
  onData(stream, session, callback) {
    const { envelope } = session;
    console.log("From:", envelope.mailFrom && envelope.mailFrom.address);
    console.log("To:", envelope.rcptTo.map((r) => r.address));
    console.log("Secure:", session.secure);
    console.log("User:", session.user);

    stream.pipeTo(new WritableStream()).then(() => callback(null), callback);
  },
});

Released under the MIT License.