Creating an SMTP server
In this recipe, we'll create our internal SMTP server (just like the first SMTP servers) using the smtp-protocol
module.
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 folder called smtp-server
, with an index.js
file.
Then on the command-line from within the smtp-server
directory, we can initialize our folder and install the smtp-protocol
module:
$ npm init -y $ npm install --save smtp-protocol
How to do it...
Let's start by requiring the relevant dependencies:
const fs = require('fs') const path = require('path') const smtp = require('smtp-protocol')
We're only going to accept emails to certain host domains, and only for certain users. We also need somewhere to store the emails we have accepted.
So let's create two whitelist sets, one for hosts and the other for users, along with a target path for mailboxes:
const hosts = new Set(['localhost...