Creating an SMTP server
We don't have to rely on a third-party SMTP server, we can create our own!
In this recipe, we'll create our own internal SMTP server (just like the first SMTP servers) using the third-party simplesmtp
module which is an underlying library of the nodemailer
module from the first recipe of this chapter, Sending email. For information on converting an internal SMTP server to an externally exposed MX record server, see the There's more... section at the end of this recipe.
Getting ready
Let's create a file and call it server.js
, then make a new folder called mailboxes
, containing three subfolders: bob, bib
, and susie
. We'll also want to have our mailout.js
file from the first recipe to hand.
How to do it...
First, we'll set up some initial variables:
var simplesmtp = require('simplesmtp'); var fs = require('fs'); var path = require('path'); var users = [{user: 'node', pass: 'cookbook'}], mailboxDir = './mailboxes/', catchall = fs.createWriteStream(mailboxDir + 'caught', ...