If you are doing web development there is often need to emulate and intercept outgoing email. Email delivery is handled by SMTP protocol. Production and staging server have fixed SMTP servers available in their network. However, this is not often the case for your development laptop, especially if you tend to do development in different networks (places).
Python comes with simple smtpd module which allows you to run a simple SMTP server easily. When doing email debugging, smtpd has extreme useful DebuggingServer feature making it dump all relayed email to stdout instead of relaying them forward for email delivery. This approach is compatible on all platforms: Windows, OSX and Linux.
Non-root way to run debugging SMTP server. You need to change the SMTP server details in your application settings to localhost:1025:
python -m smtpd -n -c DebuggingServer localhost:1025
If you want to bind SMTP port 25 you need to run this as a root:
sudo python -m smtpd -n -c DebuggingServer localhost:25
Now, when your application sends email it is printed to terminal running debugging smtpd:
---------- MESSAGE FOLLOWS ---------- Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [example.com] Confirm your email From: test@example.com To: mikko@example.com Date: Fri, 26 Apr 2013 07:20:34 -0000 Message-ID: <20130426072034.83439.2762@Kohr-Ah.local> X-Peer: 127.0.0.1 Test output from smtpd ------------ END MESSAGE ------------
Alternative you can go for a full stack solution and install Postfix with external authenticating mail server.
Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+
Thanks a lot – thats a fantastic hint!
Hi,
You can use dsmtpd
https://github.com/matrixise/dsmtpd
Regards,
Stephane
Pingback: In the News: 2013-04-26 | Klaus' Korner
Sweet. I didn’t know this was possible and had been using a gmail account for debugging email from my django app. Thanks for the tip!
I love python -m. Amazing what it can do.
Pingback: On a roll with the Free SMTP Server! | Hosting Home
Pingback: SMTP Servers – How Do They Work | Hosting Home
If you have python and pip installed, you can use PyLocalSmtp, a web interface that uses the core python DebuggingServer https://pypi.python.org/pypi/pylocalsmtp/1.0.0
Nice tip!
Pingback: 我的Flask开发环境 | Tiz Grape