Debugging SMTP

I saw this today on djangosnippets and figured it’s useful enough for me to post! Sometimes when writing a webapp you need to debug the output of your e-mail sending. This can be quite hard as things have to, usually, go via an SMTP server. What you really want is a quick way to grab the output with all the headers that YOUR code is setting – you can, easily, with Python.

OSX/Unix/Linux

sudo /usr/lib/python2.5/smtpd.py \
    -n -c DebuggingServer localhost:25

(obviously on Solaris/OpenSolaris you want to use pfexec instead of sudo!)

Windows

c:\python25\python.exe c:\python25\lib\smtpd.py \
    -n -c DebuggingServer localhost:25

You then get an output in the terminal window you ran it in every time a message hits the server. Handy.

Subscribe

Subscribe to our e-mail newsletter to receive updates.

2 Responses to Debugging SMTP

  1. David Rickard September 9, 2008 at 6:36 pm #

    That’s insanely useful. I assume it can listen on other addresses, i.e. could sit there picking up mail from another host? Useful none the less :)

  2. Einars September 10, 2008 at 2:10 am #

    Extending the idea of sent mails debugging, quite a long time ago I wrote a little debugging script, which you can download at http://elfz.laacz.lv/fakemail.py — it’s much like your suggestion, only it acts as a POP3 server as well, so you can use your mail client to download sent messages and see how they came out. Maybe you could find it useful.

Leave a Reply