Over a million developers have joined DZone.

Debug SMTP Server One-Liner

· DevOps Zone

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

If you are doing web development there is often a 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.

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:

Published at DZone with permission of Mikko Ohtamaa, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}