<!---
This example uses a table called EmailTemplates with the following columns
`ID` INT(11)
`sender` VARCHAR(255)
`subject` VARCHAR(255)
`htmlbody` BLOB //The html pages are stored in this column
`textbody` BLOB //The text pages are stored in this column
--->
<!--- Set defaults --->
<cfparam name="mailto"
default="[Email Address]">
<cfparam name="mailID"
default="59">
<cfparam name="path_to_file"
default="C:\path_to_file\">
<cfparam name="DSN"
default="MYDSN">
<!--- Create a random filename for the html doc--->
<cfset html_file = #RandRange(1000,100000)#&'.cfm'>
<!--- Create a random
filename for the text doc--->
<cfset text_file = #RandRange(1000,100000)#&'.cfm'>
<!--- Query the
database for the proper email to send, choose your own criteria --->
<cfquery datasource="#MYDSN#"
name="getliterature">
SELECT * FROM EmailTemplates WHERE ID = #mailID#
</cfquery>
<!--- Write the
temporary file with the HTML contents of the email body --->
<cffile action="write"
nameconflict="makeunique"
file="#path_to_file##Variables.html_file#"
output="#getliterature.htmlbody#">
<!--- Write the
temporary file with the TEXT contents of the email body --->
<cffile action="write"
nameconflict="makeunique"
file="#path_to_file##Variables.text_file#"
output="#getliterature.textbody#">
<!--- Save the
variable with the contents of the saved HTML file --->
<cfsavecontent variable="HTMLBody">
<cfoutput>
<cfinclude template="#Variables.html_file#">
</cfoutput>
</cfsavecontent>
<!--- Save the
variable with the contents of the saved TEXT file --->
<cfsavecontent variable="TextBody">
<cfoutput>
<cfinclude template="#Variables.text_file#">
</cfoutput>
</cfsavecontent>
<!--- Send the mail
message--->
<cfmail to="#mailto#"
from="#getliterature.sender#"
subject="#getliterature.subject#"
type="html">
<cfmailpart type="html">
#HTMLBody#
</cfmailpart>
<cfmailpart type="text">
#TextBody#
</cfmailpart>
</cfmail>
<!--- Delete the temporary file created earlier --->
<cffile action="delete"
file="#path_to_file##Variables.html_file#">
<cffile action="delete"
file="#path_to_file##Variables.text_file#">