Setting up a simple smtp server for testing

On many websites, there is a need for sending mail from the webserver. While testing, it’s sometimes painful to get a working smtp server to test this.

I’ve used this script for a while now, since it’s the simplest way to get a mailserver running. It will accept any smtp connection and print the mail to the terminal where you started it from.

The script:

import smtpd, asyncore
print 'Mailserver is on port 8025. Press ctrl-c to stop.'
server = smtpd.DebuggingServer(('localhost', 8025), None)
asyncore.loop()

Place those four lines into a python file (I used dummymailserver.py) and then run the python file:

python dummymailserver.py

And you’re done!