Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
smtp-server-as-promised
Advanced tools
Changelog
v5.2.5 2019-10-08
mocha-steps
for testing.Readme
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.
This module requires Node >= 6.
npm install smtp-server-as-promised
Additionally for Typescript:
npm install -D @types/node @types/nodemailer @types/smtp-server
smtp-server-as-promised
can be used like standard smtp-server
module:
const {SMTPServerAsPromised} = require("smtp-server-as-promised")
class MySMTPServer extends SMTPServerAsPromised {}
Typescript:
import SMTPServerAsPromised from "smtp-server-as-promised"
// or
import {SMTPServerAsPromised} from "smtp-server-as-promised"
class MySMTPServer extends SMTPServerAsPromised {}
const server = new MySMTPServer(options)
Create new SMTPServerAsPromised
instance.
Example:
const server = new MySMTPServer({
disabledCommands: ["AUTH"],
})
Options are the same as for original smtp-server
constructor except callback
handlers that methods of this class should be used instead.
This method can be overriden in subclass.
Example:
class MySMTPServer extends SMTPServerAsPromised {
async onConnect(session) {
console.log(`[${session.id}] onConnect`)
}
}
This method can be overriden in subclass.
Example:
class MySMTPServer extends SMTPServerAsPromised {
async onAuth(auth, session) {
if (auth.method === "PLAIN" && auth.username === "username" && auth.password === "password") {
return {user: auth.username}
} else {
throw new Error("Invalid username or password")
}
}
}
This method must return the object with user
property.
This method can be overriden in subclass.
Example:
class MySMTPServer extends SMTPServerAsPromised {
async onMailFrom(from, session) {
console.log(`[${session.id}] onMailFrom ${from.address}`)
if (from.address.split("@")[1] === "spammer.com") {
throw new Error("we do not like spam!")
}
}
}
An errors can be thrown and then are handled by server in response message.
This method can be overriden in subclass.
Example:
class MySMTPServer extends SMTPServerAsPromised {
async onRcptTo(to, session) {
console.log(`[${session.id}] onRcptTo ${to.address}`)
if (from.address.split("@")[1] === "spammer.com") {
throw new Error("we do not like spam!")
}
}
}
This method can be overriden in subclass.
Example:
class MySMTPServer extends SMTPServerAsPromised {
async onData(stream, session) {
console.log(`[${session.id}] onData started`)
if (stream.sizeExceeded) throw new Error("Message too big")
stream.pipe(process.stdout)
}
}
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.
This method can be overriden in subclass.
Example:
class MySMTPServer extends SMTPServerAsPromised {
async onError(error) {
console.log("Server error:", error)
}
}
const promise = server.listen(options)
Start the server instance. Argument is the same as for
net.listen
method. This method returns promise which resolves to address
value.
Example:
async function main() {
const address = await server.listen({port: 2525})
console.log(`Listening on [${address.address}]:${address.port}`)
}
const promise = server.close()
Stop the server from accepting new connections.
Example:
async function main() {
// ...
await server.close()
console.log(`Server was stopped`)
}
server.updateSecureContext(options)
Update TLS secure context.
Example:
server.updateSecureContext({key: tlsKeyPem})
await connection.destroy()
Manually free resources taken by server.
Copyright (c) 2016-2019 Piotr Roszatycki piotr.roszatycki@gmail.com
FAQs
Promisify smtp-server module
The npm package smtp-server-as-promised receives a total of 57 weekly downloads. As such, smtp-server-as-promised popularity was classified as not popular.
We found that smtp-server-as-promised demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.