Tom Mollerus' Projects: EmailParse CFC

For certain tasks at work related to customer email, we found that real-time email processing had some clear advantages over an intermittent scheduled task using CFPOP. For instance, it's great if emails are forwarded immediately instead of only when the scheduled task is run. The same goes for autoresponses. Also, there are quite a few problems with CFPOP-- if the POP account gets locked or has too many emails, the CFPOP task could time out before processing all of the messages.

If you ever need to process raw emails directly in ColdFusion instead of retrieving them via CFPOP, you should consider using EmailParse.CFC. It offers the ability to take a raw email in text format, parse it into headers, body parts, and attachments, and to forward it on to another address. There's even a function for trying to determine whether the message is a hard bounce, soft bounce, out-of-office reply, or an unknown type. Requires ColdFusion 7.

The CFC is called like so (replace the variable names in brackets with your own appropriate values):

<!--- Parse the email --->
<cfset email = CreateObject('component', 'emailParse').init('[full email source]') />

<!--- If the email is a bounce --->
<cfif email.getMeaning() eq 'Hard bounce' or email.getMeaning() eq 'Soft bounce'>
	<!--- Perhaps track bounces in your database --->
<cfelse><!--- Else the email isn't a bounce --->
	<!--- Forward it on to the person who needs it --->
	<cfset email.forward('') />
	<!--- Send an autoresponse back to the sender --->
	<cfmail subject="[Autoresponse] #email.subject#" to="#email.from#" from="" >Thanks for contacting our support department...</cfmail>

Download the code or try the demo.