micromta

Lightweight Mail Transfer Agent (SMTP server) for node.js. Inbound mail only.

Usage no npm install needed!

<script type="module">
  import micromta from 'https://cdn.skypack.dev/micromta';
</script>

README

microMTA

microMTA / µMTA

workflow npm npm NPM

microMTA is a Mail Transfer Agent (MTA) library for node.js that focuses on receiving messages. The only feature of microMTA is message receiving. No sending or relaying will be possible since the library itself is not designed to handle that.

microMTA was created for testing e-mail sending in an application, by mocking a SMTP server. By default it runs on port 25 (which requires superuser privileges or an authbind/setcap setup).

The library is available in npm, use yarn add micromta or npm install micromta to install.

Parser Builder
letterparser letterbuilder

Example

const mta = new microMTA();
mta.on('message', message => console.log(message));

// Later:
mta.close();

message will be of the type microMTAMessage:

export interface microMTAMessage {
  recipients: string[];
  sender: string;
  message: string;
}

The message is a raw message that needs to be parsed. letterparser can be used to parse and extract data from the raw messages.

Options

The constructor for microMTA accepts an options object.

Property Default value Description
ip 0.0.0.0 IP address to bind to.
port 25 Port to bind to. (Ports under 1024 usually require superuser privileges.)
hostname localhost Hostname advertised by the SMTP server.
size 1000000 Maximum message size (in bytes).
tls undefined createSecureContext options for STARTTLS support.
tlsPost 465 Port for secure only communication, only enabled if tls is configured properly.
authenticate undefined Authentication function. See Authentication for more details.

Events

message

Emitted when a message is succesfully received.

error

Emitted when an error occurs.

rejected

Emitted when a message is rejected. For now, this only happens when the message exceeds the maximum size.

Authentication

microMTA supports PLAIN and LOGIN methods for SMTP authentication. To enable authentication, a function of following type must be passed with the options object:

  authenticate?: (
    connection: microMTAConnection,
    username: string,
    password: string,
    authorizationIdentity?: string
  ) => boolean | Promise<boolean>;