Skip to content

Instantly share code, notes, and snippets.

@jsteenkamp
Created January 19, 2012 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsteenkamp/1642551 to your computer and use it in GitHub Desktop.
Save jsteenkamp/1642551 to your computer and use it in GitHub Desktop.
<cfcomponent name="PostMarkAPI" hint="Send email messages using Postmarkapp.com 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="xxx@xxx.com" />
<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)" />
<cfscript>
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];
}
}
</cfscript>
<!--- send to Postmarkapp --->
<cfhttp method="post" url="https://api.postmarkapp.com/email" 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)#" />
</cfhttp>
<!--- status code --->
<cfreturn {'statusCode' = response.statusCode} />
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment