ronny.haryan.to

Icon

Print: $9.50 — Online: free

Mail Testing Tricks

Here are some MTA (mail server) tricks that I use at work for testing an email application that we’re working on.

I wanted to do a rough benchmarking on how fast our email app can pump messages to the MTA. Of course I don’t want to actually send the emails, I don’t care where it’s sent to or what the content is, the MTA should just accept then drop them straight away.

I’m using Postfix. So I have the email app send 50,000 emails to x@blackhole.localdomain, where x is a number between 1 and 50,000. You can also do this easily with smtp-source program that comes with Postfix. In /etc/hosts I added 127.0.0.1 blackhole.localdomain, and then I set $transport_maps to hash:/etc/postfix/transport and in /etc/postfix/transport I added blackhole.localdomain blackhole: and ran postmap /etc/postfix/transport. This will make everything sent to blackhole.localdomain to be sent via the ‘blackhole’ transport, which we need to define in master.cf as follows:

blackhole unix  -       n       n       -       -       pipe
    user=nobody argv=/bin/true ${user}

The mail logs should tell us whether it’s working or not.

Another thing that sometimes I wanted to do is to capture the actual emails sent after it reaches the MTA but without the MTA actually sending the mail to the recipients. This is to get a better picture of how the emails will look like to the recipients. This is useful, for example, to verify that headers, newlines, charset, encoding, MIME, etc. are generated correctly. With Postfix, I used content_filter and did something like this in master.cf.

pickup    fifo  n       -       -       60      1       pickup
    -o content_filter=dbgcapture
20025     inet  n       -       -       -       -       smtpd
    -o content_filter=dbgcapture
20026     inet  n       -       -       -       -       smtpd
    -o debug_peer_list=127.0.0.1,192.168.1.0/24
    -o content_filter=dbgcapture
dbgcapture unix  -       n       n       -       -       pipe
  flags=FR user=ronny argv=/usr/bin/tee -a /tmp/capture.mbox

Mails sent via SMTP to $inet_interfaces:20025 and sent via /usr/sbin/sendmail will be captured in /tmp/capture.mbox. Similarly, port 20026, with additional SMTP debugging in the logs. Port 25 still works as usual. If you don’t want /usr/sbin/sendmail to go to dbgcapture simply comment out the -o content_filter line right after the pickup line. Note that using /usr/bin/tee here may not be the most efficient/correct. It works most of the time, but it’s asynchronous and it doesn’t guarantee all mails will be written in the correct order (or at all) in the mbox. If you can suggest a better way with similar level of ease, please let me know.

I was also looking at capturing mails with Sendmail. It’s possible using MIMEDefang milter with action_quarantine_whole_email() followed by action_discard(). It works but somehow it ran slower than a snail. I’m not that familiar with Sendmail. Meh. No big deal. I left the tests running, I went home, and check the test results the next morning.

In the next few months we will be doing a lot more of this kind of tests, so I’m planning to do similar thing with qmail and Exim to cover a lot more base.

Category: Linux, Tips

Tagged:

Comments are closed.

About

Ronny Haryanto is a technology addict/chef wannabe living in beautiful Melbourne, Australia.

Read more…

Follow Me on Twitter

Follow @ronny on Twitter where I post much more often than my blog.