I do many things, one of them is creating web applications. Being able to fully test and exercise an application in an isolated test environment is crucial to creating robust code.
An application can interact with may other systems. I consider those systems to be part of one of two categories, Read-Only and Read-Write. It is just fine for your production, test, and development systems to access a read-only system. The app cannot do any harm to these systems, have at it. Read-only systems would be Identity Directories such as Active Directory or LDAP, data feeds like weather, things of that nature. A Read-Write system is something like a database or SMTP. Your app writes to these systems and if your testing data was fed into a production system it could have minor or grave consequences depending on the data and system.
Usually we have separate web servers and database servers for test and development, but SMTP seems to be forgotten. Every development shop I come into does not isolate SMTP. The solution was to set up fake emails or to change email addresses to the tester’s. For me this is not good enough. Fake emails might go to a real person, and often we will restore production data to a test system to reproduce a bug, now you have a ton of real email addresses in your data!
Long ago I defined my own requirements for a development/testing mail server. It would accept any email sent to it thru SMTP and dump it into a single mailbox. There would be a way to look at that mail box, with with an email client or a web interface. Several times a year I would scour the web looking for such a product but found nothing. I had considered setting up my own SMTP server plus web-mail for this purpose but never got around to it.
Well a few months ago I discovered MailDev. It does exactly what I want, expect one thing… run all the time as a service. These are the steps I took to combine MailDev with NSSM to get what I need.
- Windows (https://www.microsoft.com/en-us/windows/)
- Node.js/NPM (https://nodejs.org/en/download/)
- MailDev (http://danfarrelly.nyc/MailDev/)
- NSSM (http://nssm.cc/download)
I used PowerShell and installed on my secondary storage device D:. Your shell and drive will differ depending on what you use.
Download and install Node.js. I recommend a 64-bit LTS version. Use the default options with install NPM and place Node in your path.
Create a folder to store MailDev and NSSM
PS D:\> mkdir MailDev
PS D:\> cd MailDev
PS D:\MailDev> npm install maildev
Allow install to finish. I ignored the errors about missing package.json, description, etc.
PS D:\MailDev> node .\node_modules/maildev/bin/maildev
You see the MailDev app is running on port 1080 and SMTP is running on 1025.
Open a web browser and go to http://localhost:1080/ to see the MailDev app.
Back in Powershell press: Ctrl + C to exit MailDev.
Setup MailDev to run as a Windows Service
Download NSSM. I got the current stable version of 2.2.4.
Open downloaded zip file, extract the nssm-2.2.4 folder into D:\MailDev.
PS D:\MailDev> D:\MailDev\nssm-2.24\win64\nssm.exe install MailDev "C:\Program Files\nodejs\node.exe" "D:\MailDev\node_modules\maildev\bin\maildev"
You may get the warning “Administrator access is needed to install a service” and get a User Access Control dialog asking you to allow this to install. Select Yes. If you don’t see this behavior you may just need to run Powershell as Administrator before running this command.
Go to to Services and see you new MailDev entry. Start the service. Go to http://localhost:1080/ again. Setup your apps to send mail to this computer on port 1025. You might need to adjust firewall rules.