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

mbr-smtp

v1.3.1

Published

MadBrozzeR's SMTP server and client

Downloads

2

Readme

mbr-smtp

SMTP (Simple Mail Transfer Protocol) client and server implementation.

Server

const server = new Server(params = {}, listeners = {});

Create new SMTP server instance.

params - Server parameters.

listeners - Optional. Set of event listeners.

params

const params = {
  name: 'example.domain',
  port: 25,
  host: '0.0.0.0',
  size: 30 * 1024 * 1024,
  timeout: 0
}

Set of SMTP server parameters.

name - Server domain name.

port - Optional. Server port to listen to. Default: 25.

host - Optional. Host to listen connections from. Default: '0.0.0.0' (accept all).

size - Optional. Maximum message size to accept. Set 0 to disable limit. Default: 31457280 (30 Mb).

timeout - Optional. Connection timeout before socked is being closed. Set 0 to disable. Default: 0.

listeners

const listeners = {
  // Server events. Receives SMTP server instance as `this`.
  start: function () {},
  stop: function () {},
  error: function (error) {},

  // Client events. Receives Session instance as `this`.
  connect: function (socket) {},
  disconnect: function (socket) {},
  timeout: function () {},
  message: function (message) {},
  response: function (response) {},
  helo: function (origin) {},
  mail: function ({ from, size }) {},
  rcpt: function (email) {},
  dataStart: function () {},
  dataChunk: function (chunk) {},
  data: function (data) {},
};

Set of server related event listeners.

start - Server is ready to listen to connections.

stop - Server is stopped.

error - Some unexpected error occured.

Set of client related event listeners. Most of them are interruptable, so make sure you triggered this.success(), this.failure() or this.ok() inside any listener that has been added. Or just return true to proceed default command execution. Otherwise client won't get any response.

connect - (interruptable) Client connected.

disconnect - Client disconnected.

timeout - (interruptable) Idle timeout was triggered.

message - (interruptable) Any client command (before it's proceeded).

response - All server responses being sent to client.

helo - (interruptable) Client sent HELO or EHLO command with it's origin (domain).

mail - (interruptable) Client sent MAIL command with it's email and optionally expected data size.

rcpt - (interruptable) Client sent RCPT command with destination's email.

dataStart - (interruptable) Client initialized message transfer.

dataChunk - Client sent some data in DATA block.

data - (interruptable) Client provided it's message.

Alternatively listeners argument can be set as function instead of object. It will accept two arguments: type (one of types above as string) and an argument. This function should return true if no interruption intended. Example:

const listeners = function (type, param) {
  switch (type) {
    case 'start':
      // Do something on server start
      break;

    case 'data':
      const sessionData = this.data; // `this` is a session instance
      const message = param;
      // Do something
      this.success();
      break;
  }

  return true; // required to proceed default behavior
}

Server instance methods

server.on(listeners);

Attach listeners to events. You can attach them either here, or in Server constructor.

server.start();

Start server to listen to connections.

server.stop();

Stop server from listening to connections.

Session instance

Client session collecting all required data during current connection. It's being passed to all client listeners.

session.id

Random generated session ID.

session.socket

Session client socket

session.smtp

Link to SMTP server instance.

session.queue

NetQueue instance with current operations.

session.send(code, message)

Send custom server response.

session.success([message])

Trigger success event with default command behavior and proceed communication. If no message is provided default one will be used.

session.ok([message])

Trigger success event skipping default command behavior (session.data object is not filled) and proceed communication. If no message is provided default one will be used.

session.failure(code, message)

Trigger error event and proceed communication. Send client failure reason.