smtp-server-as-promised
This module provides promisified version of
smtp-server
module. The API is
the same as for smtp-server
, except listen
method which return
Promise
object and callback options which should be replaced with overriden method in
own subclass.
Requirements
This module requires Node >= 6.
Installation
npm install smtp-server-as-promised
Additionally for Typescript:
npm install -D @types/node @types/nodemailer @types/smtp-server
Usage
smtp-server-as-promised
can be used like standard smtp-server
module:
const SMTPServerAsPromised = {}
Typescript:
// or
constructor
const server = options
Create new SMTPServerAsPromised
instance.
Example:
const server = disabledCommands: "AUTH"
Options are the same as for original smtp-server
constructor except callback
handlers that methods of this class should be used instead.
onConnect
This method can be overriden in subclass.
Example:
async { console }
onAuth
This method can be overriden in subclass.
Example:
async { if authmethod === "PLAIN" && authusername === "username" && authpassword === "password" return user: authusername else throw "Invalid username or password" }
This method must return the object with user
property.
onMailFrom
This method can be overriden in subclass.
Example:
async { console if fromaddress1 === "spammer.com" throw "we do not like spam!" }
An errors can be thrown and then are handled by server in response message.
onRcptTo
This method can be overriden in subclass.
Example:
async { console if fromaddress1 === "spammer.com" throw "we do not like spam!" }
onData
This method can be overriden in subclass.
Example:
async { console if streamsizeExceeded throw "Message too big" stream }
stream
object is a
stream.Duplex
object with additional properties: byteLength
and sizeExceeded
.
The method blocks SMTP session until stream
is finished. It breaks session if
stream
is already finished.
If the method throws an error then the stream
is silently consumed to
prevent SMTP stream to be blocked.
onError
This method can be overriden in subclass.
Example:
async { console }
listen
const promise = server
Start the server instance. Argument is the same as for
net.listen
method. This method returns promise which resolves to address
value.
Example:
{ const address = await server console}
close
const promise = server
Stop the server from accepting new connections.
Example:
{ // ... await server console}
updateSecureContext
server
Update TLS secure context.
Example:
server
destroy
await connection
Manually free resources taken by server.
License
Copyright (c) 2016-2019 Piotr Roszatycki piotr.roszatycki@gmail.com