1 for the money, 10 for the show.
The browser you're using has Javascript turned off. This web page will still work, but it'll work even better if you turn scripting on. Find out how here.
The else{rss} feed will tell you when new geek bits are added to this page. You can click here to subscribe.
 
Subscribe to the else{rss} feed

New geek bits ?

IT ideas, solutions, designs ... gosh, possibly even actual code and software.

You can click the green links at the right to view different subjects. The freshest content is always displayed first, so if what you immediately see isn't new to you, check back later.

If you haven't already read it, check out Harnessing your web history.

Dynamic Email Signatures
Sunday 1 March 2009

Richard is a Windows Mail user. He's pointed out for some time how my plain text signature has a corrupting influence on the body of my email messages. While a better email client might fix this for him, his most recent example coincided with a wet Saturday afternoon, so I set out to create an HTML signature - a change was clearly overdue.

I thought my new signature should match the style of this website, and my next thought was "and it should contain dynamic content too, just like the website". Oops. Scope creep.

My email client is Thunderbird, running on Windows XP, but the following project could be adapted to most email clients with a little ingenuity. It allows me to generate dynamic email signatures, and at the same time avoid duplicating and maintaining data.

Here's what my new signature looks like.

The first two items in the What else is fresh? column are dynamic, and so is the quotation at the bottom. The entire signature is generated by a PHP routine hosted on my website, where I already store and present this data in different forms. The result is that every email message I compose has a slightly different signature, but I don't have to manage the source data in an additional location.

Here's how I did it.

Thunderbird signatures are text files which may contain plain text or HTML. If it were possible to load the signature files from a URL, inclusion of dynamic content would be simple. Sadly the Bird only supports the local file system.

A little research took me to a Thunderbird add-on called Signature Switch which allows the inclusion of "fortune cookie" content. I could have used this to create the dynamic content I wanted, but it would have meant migrating the quotations from a MySQL table on the website where they seemed perfectly happy, and duplicating the data in a server RSS file which I already parse for the site's What's new section.

I could have avoided duplication by writing a Windows utility to refresh the signature file periodically, perhaps in response to system notification of the file being accessed, but I didn't have any development environment on my laptop.

Yes, it does seem unlikely. But I've mislaid my Delphi install disc - phone me if you know where it is - and deliberately restrict Eclipse and SharpDevelop to my desktop because they're such resource hogs. I do most my web development, incidentally, in the delightful PSPad.

But Signature Switch provides a better answer anyway. On its Advanced tab it allows an executable file to be run before each signature file is loaded. An executable file? Enter the wonderful wget.exe.

wget.exe is a cross-platform utility that does one task exceptionally well; it retrieves web content and writes it to the local hard drive. It accepts command line parameters, or more complex tasks can be written to a file with multiple entries.

I chose to drive wget.exe with a batch file because it made testing easier and meant I could have the various parts of the puzzle installed in different locations on different computers.

And here's what happens.

When I click the Compose button in Thunderbird, Signature Switch tells wget.exe to download the specified PHP file from my website. This PHP file generates a new HTML signature including dynamically-created content taken from database tables and my RSS file, and wget.exe takes the resulting stream and overwrites my signature file. Easy peasy.

After I'd verifed that everything worked as it should, my final step was to uncheck the Wait for executable to finish option in Signature Switch. Now when I click Compose in Thunderbird, the new message opens immediately using the previously-loaded signature file, while wget.exe begins downloading the next signature in the background. It's quicker.

If I'm ever off-line I still have the previously-downloaded signature file - wget.exe won't overwrite it if it can't access the replacement. One major risk tidily mitigated.

It would be possible to include more dynamic content in my email signature. I could use cURL and RSS feeds to insert Wellington weather; I could generate different signatures for different contexts; and I could include links to randomly-chosen articles like this one.

I suspect there may be a few refinements ahead.

If you liked this post
Share/Bookmark
share it around.
If you really liked this post
a small donation helps.
If you liked this post a lot
Subscribe
don't miss the next one.
 
author
LeighLeigh Harrison is currently repaying karma from a past life by working as an IT Generalist in this one.

Leigh lives in New Zealand where she develops web applications and desktop software and manages development projects for clients around the globe. To get a CV send an email or phone +6421 933 913.

In her spare time, and sometimes in other peoples, Leigh writes and occasionally performs music. She hopes to play soccer again next season if her knee will get with the plan.
 
quote
The purpose of art: to make the unconscious conscious.
• Richard Wagner
 
links

website
Created by filling a plain text editor with HTML, CSS, PHP, XML, AJAX and any other acronyms that were looking for a good time. There's Javascript, sure, but not in your browser.