Articles

Support Unlimited Forwarded Email Messages via API (and ColdFusion)

Forward Email Webhook and Taffy API

Convert email to JSON using Forward Email webook and Taffy API
May 8, 2025

We have clients that use dedicated email addresses to receive and process messages and attachments. I had previously developed some functions to bulk download EML files directly from a mail server's file system (using FastCopy) and then use "javax.mail" and a lot of crazy logic to unwrap attachments within attachments to extract files for processing. (Most file attachments were being sent from different versions of a required iPhone app on different devices and the methods of attaching files was not consistent.) Hit me up if anyone's interested in extracting attachments from EML files.

While researching alternative solutions, we came across Forward Email. They offer a free tier that supports unlimited domains and email forwarding with webhook support. Webhook? Wha? Really? AMAZING!

When configuring a domain on the free tier for a webhook, you're required to add a special TXT "forward-email" DNS record in order to configure the endpoint. They have an option to encrypt the value so that it's not exposed to third-parties. If you want to configure it using their service (without the need to add it to DNS), you'll need a $3/mo "Enhanced" plan that also unlocks developer API access (to manage domains & aliases.)

After configuring this service, we opted to set up a Taffy API endpoint to accept emails-as-JSON and save them to the local file system. Based on our experience working with SendGrid webhooks, we save the JSON payload directly to the local file system without being dependent on a database connection. This approach has been beneficial as a client recently encountered database issues and it had zero negative impact on the API webhook's ability to store incoming data.

After some additional testing, we'll release a CFC wrapper to manage Forward Email's domains & aliases via their API.

Here's the drop-in source code for the Taffy API framework.

component extends="taffy.core.resource" taffy_uri="/forwardEmail/{domainName}" {
	// This is a Taffy Webhook endpoint.
	// Requires the Taffy framework: https://taffy.io/ https://github.com/atuttle/Taffy
	// Configure email to be sent to https://yourdomain.com/forwardEmail/yourdomain_com

	variables.rootDir = "d:\forwardEmail\inbox";
	
	public function post(string domainName="unknown") output=false {

		local.formBody = javacast("string", gethttprequestdata().content);

		if (!len(trim(local.formBody))){
			return noData().withStatus(200).noCache();
		}

		filewrite("#variables.rootDir#\#domainKeystring(arguments.domainName)#-#datetimeformat(now(),'yyyymmddHHnnsslll')#.json", local.formBody, "utf-8");

		return noData().withStatus(200).noCache();
	}

	private string function domainKeystring(required string inputString){
		return lcase(tostring(trim(arguments.inputString)).replaceAll("[^a-zA-Z0-9]", "_"));
	}
}