NOTICE: This project will no longer be maintained, please use @typemail/smtp
instead.
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 |
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.
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. |
Emitted when a message is succesfully received.
Emitted when an error occurs.
Emitted when a message is rejected. For now, this only happens when the message exceeds the maximum size.
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>;