Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple SMTP server/client module
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
jsdoc
lib
test
.gitignore
.travis.yml
LICENSE
README.md
package.json
run_tests.js

README.md

simplesmtp

This is a module to easily create custom SMTP servers - use SMTP as a first class protocol in Node.JS!

Build Status

Autogenerated docs

Usage

Create a new SMTP server instance with

var smtp = new SMTPServer([options]);

And start listening on selected port

smtp.listen(25, [function(err){}]);

SMTP options can include the following:

  • HOSTNAME - the hostname of the server, will be used for informational messages
  • debug - if set to true, print out messages about the connection
  • timeout - client timeout in milliseconds, defaults to 60 000 (60 sec.)
  • SMTPBanner - greeting banner that is sent to the client on connection
  • requireAuthentication - if set to true, require that the client must authenticate itself
  • validateSender - if set to true, emit 'validateSender' with email and callback when the client enters MAIL FROM:<address>
  • validateRecipients - if set to true, emit 'validateRecipient' with email and callback when the client enters RCPT TO:<address>
  • maxSize - maximum size of an e-mail in bytes (currently informational only)
  • credentials - TLS credentials ({key:'', cert:'', ca:''}) for the server
  • authMethods - allowed authentication methods, defaults to ["PLAIN", "LOGIN"]

Example

var SMTPServer = require("simplesmtp").SMTPServer,
    fs = require("fs");

var smtp = new SMTPServer();
smtp.listen(25);

smtp.on("startData", function(envelope){
    console.log("Message from:", envelope.from);
    console.log("Message to:", envelope.to);
    envelope.saveStream = fs.createWriteStream("/tmp/message.txt");
});

smtp.on("data", function(envelope, chunk){
    envelope.saveStream.write(chunk);
});

smtp.on("dataReady", function(envelope, callback){
    envelope.saveStream.end();
    console.log("Incoming message saved to /tmp/message.txt");
    callback(null, "ABC1"); // ABC1 is the queue id to be advertised to the client
    // callback(new Error("That was clearly a spam!"));
});

Events

  • startData (envelope) - DATA stream is opened by the client (envelope is an object with from, to, host and remoteAddress properties)
  • data (envelope, chunk) - e-mail data chunk is passed from the client
  • dataReady (envelope, callback) - client is finished passing e-mail data, callback returns the queue id to the client
  • authorizeUser (envelope, username, password, callback) - will be emitted if requireAuthentication option is set to true. callback has two parameters (err, success) where success is Boolean and should be true, if user is authenticated successfully
  • validateSender (envelope, email, callback) - will be emitted if validateSender option is set to true
  • validateRecipient (envelope, email, callback) - will be emitted it validataRecipients option is set to true

License

MIT

Something went wrong with that request. Please try again.