tags:

views:

776

answers:

6

I am implementing a comment control that allows a person to select comments and have them sent to specified departments. The email needs to be formatted in a specific way, and I was wondering what the best way to do this would be.

Should I just hard code all of the style information into one massive method, or should I try and create a separate file and read it in, and then replace certain tags with the relevant information?

+5  A: 

Find and use some kind of template library, if possible. This will make each email a template which will then be much easier to maintain than the hardcoded form.

pjz
A: 

I would use a template approach. It wouldn't he hard to create a simple regex template system, replacing something like #somevar# with the value for 'somevar'. You could also use a premade template system, like Smarty for PHP. I think that would be the cleanest approach.

Alex

Alex Fort
+3  A: 

In addition to using some sort of template, as tedious as it is, inline styles are the most cross-client compatible way of styling HTML emails. Not every email client will fetch an external stylesheet and many don't do so well with an embedded style section.

That being the case, I would choose a fairly simple set of style rules for the email in order to ensure that it looks the same in different email clients and try not to rely too heavily on images as many client will require that extra click to show content.

Wayne
A: 

I've used XLST templates in the past to format emails. Generally emails are best constructed using tables and inline CSS. Note that outlook 2007 does not support background images :(

Toby Mills
A: 

Definitely use templates. I have done it with text templates using custom tags like so:

<p>Dear |FIRST_NAME|,

But I really cannot recommend this; it is a world of pain. The second time I did it (an html email appender for log4net) I used an xslt to transform the object (in this case a log4net message) into an html email. Much neater.

Note that certain clients (e.g. Lotus Notes) do not support XHTML, so use plain old HTML 1.0, with no css, and you should be ok.

Matt Howells
+3  A: 

Campaign monitor has some great, well-tested free templates:

http://www.campaignmonitor.com/templates/

Make sure whatever you use will display well in all clients.

A great guide:

http://www.campaignmonitor.com/blog/archives/2008/05/2008_email_design_guidelines.html

Buzz