Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 12:13
Show Gist options
  • Save bennadel/9760650 to your computer and use it in GitHub Desktop.
Save bennadel/9760650 to your computer and use it in GitHub Desktop.
EmailYak.cfc - A ColdFusion Wrapper For The Email Yak API
<!--- Create an instance of the Email Yak wrapper. --->
<cfset emailYak = createObject( "component", "com.emailyak.EmailYak" )
.init( application.apiKey )
/>
<!---
When sending attachments, they need to be encoded as Base64
strings. Therefore, when we read in the binary, we simply have
to encode them.
--->
<cfset attachments = [
{
filename = "alisha_morrow.jpg",
content = toBase64( fileReadBinary( expandPath( "./attachments/alisha_morrow.jpg" ) ) )
},
{
filename = "jen_rish.jpg",
content = toBase64( fileReadBinary( expandPath( "./attachments/jen_rish.jpg" ) ) )
}
] />
<!--- Send an email with attachments. --->
<cfset response = emailYak.sendEmail(
fromAddress = "ben@emailyakcfc.simpleyak.com",
fromName = "Ben Nadel",
toAddress = "ben@bennadel.com",
subject = "This is a test from EmailYak.cfc",
htmlBody = "Email Yak, it really whips the llama's ass.",
textBody = "Email Yak, it really whips the llama's ass.",
attachments = attachments
) />
<!--- Output the response. --->
<cfdump
var="#response#"
label="Send Email Response"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment