alanwilliamson

OpenBD CFMAIL gets call back handler

An interesting idea was posted on the OpenBD Mailing list earlier this week and when you think about it, it is so obvious you wonder why we haven't done it before!

When you generate email from a CFML application, it does not necessarily get delivered there and then. Instead it goes into a spooling application that is tuned to deliver emails to the upstream MTA in an efficient and timely manner. You can opt to have the email delivered there and then, but that is a bit of a hack and doesn't scale terribly well.

CFMAIL always keeps a log of what it does, including noting the success or failure of a given email. If an email fails, then it gets moved to a "undelivered" folder where you can inspect it, or simply copy it back into the "spool" folder for it to be retried again (assuming of course you've resolved the original problem).

However, from a CFML application level, you have no real visibility into the success of this. Instead you have had to rely on inspecting the file system and log files.

No longer.

When you send out your email with CFMAIL, you can specify an optional callback attribute which takes in the name of a CFC that will be called when an email is either successfully delivered, or fails for some reason. You can see an example CFC to do this below.

<cfcomponent>
 
<cffunction name="onMailSend">
  <cfargument name="to" type="array"/>
  <cfargument name="from" />
  <cfargument name="subject" />
  <cfargument name="messageid" />
  <cfargument name="server" />
</cffunction>
 
 
<cffunction name="onMailFail">
  <cfargument name="to" type="array" />
  <cfargument name="from" />
  <cfargument name="subject" />
  <cfargument name="messageid" />
  <cfargument name="server" />
  <cfargument name="error" />
  <cfargument name="file" hint="full path to the failed file" />
  
</cffunction>
 
</cfcomponent>

Inside this CFC, you have the 'application' available to you, although you do not have 'form', 'url' or 'cgi' as they do not make much sense in that context.

In addition, we've added getMailSpoolDirectory() which returns the full path of where the spooled emails are residing.

Naturally, the callback handler works under Google App Engine as well as the standard distribution.

For more information see: http://openbd.org/manual/?/tag/CFMAIL


 

Recent Cloud posts

Recent JAVA posts

Latest CFML posts


 
Site Links