mailto: an elegant solution with limitations

On my current project (Flex and Java) the client wants to email certain data to certain recipients. If the mail content and recipients wouldn’t require manual processing, I’d written a Java server side program that would retrieve the data and sent it to a predefined list of recipients. This is not the case though. The client wants to see the data in an email client (MS Outlook) and be able to add some text to the email body, edit the To, CC, and the subject fields.

That’s why I decided to go with a client side solution. There is this handy protocol mailto, and if you’ll prepare the URL that starts like “mailto:…”, contains the To, CC, Subject, and Body – your program will obediently open the mail client with all the field pre-populated. In Flex, you need to use the function navigateToURL(), but this solution works for any programming language or HTML links. So far so good. I’ve easily implemented this elegant solution giving the client the best of both worlds – automatic mail generation with the ability to massage the text.

But my happiness didn’t last long, cause there was yet another innocent requirement – the data should be formatted. Nothing fancy – like columns in the grid. For example, the email body could have contain the following part:

John Smith                5,678
Mary Lou                        12
B Ramalinga Raju          101

Not a rocket science, right? I also though so and quickly wrote two functions to pad a string with spaces from the left and from the right to a certain length. Then I formed each line concatenating the right-padded 20-char long name with the left-padded 10-char long number. Quick test with printing the result in the console of my IDE – it works! What a great programmer I am, aren’t I?

After passing the same data to the mailto, it opened MS Outlook, and the mail body looked similar to this:
John Smith            5,678
Mary Lou                      12
B Ramalinga Raju         101

My perfect alignment went down the drain. And the worst part is that there is no solution to this problem. The mail client was using a font that allocated different width to each characters and my padding was resulting in different width depending on what characters presented in the name of the person. If I could pass HTML to the mailto URL, this would solve my issue. I could have used HTML Table with cell alignment. But mailto allows to pass only simple text (URL encoding didn’t help either).

I hit the wall. What’s next? Will tell the client, “I give you an elegant and flexible solution, but I can’t align the text. Either manually change the font of the data to one of the monospace font, or set Courier to be a default font in MS Outlook “. I’ve implemented lots of non-trivial solutions for this client, but hey, technology has its limits too.

What if the client answers, “No, I need perfectly aligned report and I hate Courier font?” I’ll answer, “No problem, everything can be fixed. I can certainly come up with a custom solution. It’ll take me N days to implement” After multiplying my daily rate by N the client may reconsider and agree to live with my monospace font solution. This is is good example of a situation, when there is a huge price difference between 100% and 99% automated solution.

P.S. If you run into a similar problem in the Flex TextArea component, the solution is the same – set the fontFamily attribute to use one of the monospace solutions, for example:

<s:TextArea fontFamily=”_typewriter”/>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s