Created
January 19, 2012 20:59
-
-
Save jsteenkamp/1642551 to your computer and use it in GitHub Desktop.
Refactor of Postmark CFC from https://github.com/wildbit/postmark-coldfusion/blob/master/postmarkapi.cfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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="[email protected]" /> | |
<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