All in the <head> – Ponderings and code by Drew McLellan –

Colour me Spammy

No matter how much they protest to the contrary, marketeers love sending promotional emails to their customer base. They’ll tell you it’s solicited and more than welcomed by their customers until they’re blue in the face, and just as you’re egging them on to go past blue to, well, dead, they stop to complain about another spam that has just arrived in their inbox.

As a web developer, it often falls to you to develop the applications to power their spammy evilness. At the moment I’m averaging one such system every two years or so – that’s not too bad considering marketeers are stuck with being marketeers for life. When designing such a system it quickly becomes apparent that a web app isn’t the most efficient place to be sending mail from. In terms of logistics it’s a good place to be composing the mail (you have a database of content sat right there on the site) and to assemble the ‘hit’ lists (similarly, a complete list of web site users), and so whilst you’re doing all the hard work on the site you might as well send from there too, right? That tends to be the way the decision goes, simply because investing in a second system for deploying the mailing is uneconomical.

Each time you write a bulk mailer – or spam machine as I lovingly refer to them – you get a little better at the implementation. The weakness, however, is always the process of sending the emails themselves. It nearly always comes down to some sort of loop that goes through each record in the hit list and sends a single mail. It’s time consuming and as dull as buggery. Desperate to find a solution to this, I started looking at various mailing list management tools, trying to find something I could dynamically subscribe addresses to. My thinking was that if I could assemble the hit list, I could then subscribe each address to a proper list server and have that send the mail for me. After much poking around on my web server, none of the list managers I had seemed to be able to help. It all came down to sending a ‘subscribe’ email, which rather defeated the point.

I came across the solution I was looking for through a totally unrelated conversation with the emailmeister himself, Steve Champeon. He had made mention of a mailing list that was simply based on a sendmail alias – and after a quick bit of googling I had my solution. Here’s the skinny.

Unix based systems have an inbuilt ability to alias one email address to another. It’s just something they do, and it’s usually found somewhere like /etc/aliases or /etc/mail/aliases. The format of the file is simple:

aliased-user: real-user

The handy bit for me is the fact that you can include the address of a file containing a one-per-line list of addresses for an alias to map to. The syntax goes like this:

aliased-user: :include:/home/whatever/mylist.txt

All I then needed to do was to populate mylist.txt with the addresses I wanted to send to, and then fire off an email BCC’d to aliased-user@domain.com, and the mail server does the rest. Of course, you don’t want to send directly to the list alias, as that would reveal the address to everyone on the list. To be doubly sure, I also clear out the contents of the list file once I’m done.

So, not only am I a spammer, but I’m a crafty one at that.