Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
70 lines (49 sloc) 3.13 KB


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

Build Status

Autogenerated docs


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"]
  • disableEHLO - if set to true, support HELO command only


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

var smtp = new SMTPServer();

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

smtp.on("data", function(envelope, chunk){

smtp.on("dataReady", function(envelope, callback){
    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!"));


  • 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



Something went wrong with that request. Please try again.