Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<cfcomponent name="PostMarkAPI" hint="Send email messages using API">
<cffunction name="sendMail" output="false" access="remote" returntype="struct" returnformat="json" description="Assembles JSON packet and sends it to Postmarkapp">
<cfargument name="mailTo" required="true" type="string" displayname="Recipient" />
<cfargument name="mailFrom" required="true" type="string" displayname="Sender" default="" />
<cfargument name="mailSubject" required="true" type="string" displayname="Subject" default="Testing Postmark" />
<cfargument name="apiKey" required="true" type="string" displayname="API key" default="xxx-xxx-xxx-xxx" />
<!--- optional --->
<cfargument name="mailReply" required="false" type="string" displayname="Reply-To (optional)" />
<cfargument name="mailCc" required="false" type="string" displayname="CC (optional)" />
<cfargument name="mailHTML" required="false" type="string" displayname="HTML body (optional)" />
<cfargument name="mailTxt" required="false" type="string" displayname="Plain text (optional)" />
var response = {};
var key = '';
var mail = {};
var lookup = {
'mailTo' = 'To',
'mailFrom' = 'From',
'mailSubject' = 'Subject',
'mailReply' = 'ReplyTo',
'mailCc' = 'Cc',
'mailHTML' = 'HTMLBody',
'mailTxt' = 'TextBody'
// build postmark object
for (key in arguments){
if (key != 'apiKey' && len(arguments[key])){
mail[lookup[key]] = arguments[key];
<!--- send to Postmarkapp --->
<cfhttp method="post" url="" result="response">
<cfhttpparam type="header" name="Accept" value="application/json" />
<cfhttpparam type="header" name="Content-type" value="application/json" />
<cfhttpparam type="header" name="X-Postmark-Server-Token" value="#arguments.apiKey#" />
<cfhttpparam type="body" encoded="no" value="#serializeJSON(mail)#" />
<!--- status code --->
<cfreturn {'statusCode' = response.statusCode} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment