Test SMTP with a dummy Server in Python
Today I came across a need to test SMTP outgoing emails from the web application I was working on. I was working on a simple forgotten password form that sent a password reset url to the registered user’s email address. I didn’t need to test that the email looked OK, I just needed to test the content.
Instead of setting up Exim or Sendmail and configuring it to redirect mail to my account I discovered that you can use a Python one liner to output all SMTP to the command line. Here’s how it’s done:
Test SMTP with a dummy Server in Python
sudo python -m smtpd -n -c DebuggingServer localhost:25 |
The sudo is needed as you can’t bind to a port number lower than 1024 as a normal user.
One Comment
→
Take a look at Mailtrap. It’s super easy to setup. All you have to do is to use Mailtrap SMTP server credentials in your App. You can use it in development or staging environment as well. You can view emails, share them with teammates and forward them to specific mail applications (for testing purpose). It’s free so give it a try