CSS + CFMail

A came across the dumb little trick a while back, and wanted to share this.

I like to make the mail sent from an application look like it’s part of the application, but often the step is overlooked during the development process. However by using <cfinclude> and CSS, this can be accomplished:

<cfmail to=”user@example.com” subject=”Yo!” type=”HTML” from=”anotheruser@example.com”>

<style type=”text/css”>
<cfinclude template=”[path to CSS for site]“>
</style>
[content goes here.]
</cfmail>

Granted, you have to make sure that your CSS not huge, or this becomes inefficient.

One thought on “CSS + CFMail

  1. Steve Glachan

    The include is nice a neat way of doing this, especially if your generated newsletter email is long and complex. Wrapping a <savecontent/> around the email content can also be an alternative. Then below it you would just output the ‘savecontent’ variable between cfmail tags.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>