npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smtp-server-as-promised

v5.2.5

Published

Promisify smtp-server module

Downloads

232

Readme

smtp-server-as-promised

Build Status Coverage Status npm

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} = 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 {}

constructor

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.

onConnect

This method can be overriden in subclass.

Example:

class MySMTPServer extends SMTPServerAsPromised {
  async onConnect(session) {
    console.log(`[${session.id}] onConnect`)
  }
}

onAuth

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.

onMailFrom

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.

onRcptTo

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!")
    }
  }
}

onData

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.

onError

This method can be overriden in subclass.

Example:

class MySMTPServer extends SMTPServerAsPromised {
  async onError(error) {
    console.log("Server error:", error)
  }
}

listen

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}`)
}

close

const promise = server.close()

Stop the server from accepting new connections.

Example:

async function main() {
  // ...
  await server.close()
  console.log(`Server was stopped`)
}

updateSecureContext

server.updateSecureContext(options)

Update TLS secure context.

Example:

server.updateSecureContext({key: tlsKeyPem})

destroy

await connection.destroy()

Manually free resources taken by server.

License

Copyright (c) 2016-2019 Piotr Roszatycki [email protected]

MIT