When developping web applications one often needs to send mails. It could be for example adress validation, notifications, or whatever. An underrated feature I wanted to share today is the python integrated SMTP server which could be a really good help in testing your application's mail features. Instead of having to deploy an SMTP server or you use your ISP's one, you can just type in your terminal :
python -m smtpd -n -c DebuggingServer localhost:25
This will start a local SMTP server listenning on port 25 (the default). This SMTP server will just print to stdout the mails it receive, along with headers, making your debugging easy.
Please note, that listenning to port 25 requires root privileges (it usually means to prepend sudo to the command). If you don't have such privileges on the machine you are developping you can listen on any other port superior to 1024. You then have to configure your application the use an SMTP non-default port. For example on django you would put in your settings.py :