CFMail Tracker – Application

Seems like CFMail goes wonky every once in a while and decides not to work. The administrators always blame it on too much mail for the server to handle. So I decided to call them on their “theory” and build a tracking tool.

This is a simple tool that merely writes a record to a database every time that the CFMAIL tag is used. I track not only the date and time but the application(tool_name) that sent the mail. You can add your own elements.

Step 1 – Create the tracker table
CREATE TABLE dbo.CFMail_Tracker
(
tool_name char(20) NULL,
mail_date smalldatetime NULL
)

Step 2 – Build the Component that will write the record to the table.
mail_tracker.cfc
<cfcomponent>
<cffunction name="mailtrack" access="public" >
<cfargument name="tool_name" type="string" required="true" default="NA" />
<cfquery name="insrec" datasource="bmprsql">
insert into CFMAil_Tracker
values ('#tool_name#', getDate())
</cfquery>
</cffunction>
</cfcomponent>

Step 3 – Add the code to call the cfc.
after </cfmail>
<cfinvoke component="mail_tracker" method="mailtrack" tool_name="tool name here" /> *

* You may have to adjust the path to your mail_tracker.cfc. Tool name is the application name or descriptor you wish to track.

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, Coldfusion, Problems & Fixes, SQL. Bookmark the permalink.