EmailYak.cfc - A ColdFusion Wrapper For The Email Yak API

Posted December 14, 2011 at 2:02 PM by Ben Nadel

Tags: ColdFusion

Last week, I started looking at the Email Yak API for creating bidirectional email communication between your web application and your users. In such a workflow, your users communicate with Email Yak using their native email client (GMail, Hotmail, Apple Mail, Yahoo! Mail, Outlook, etc.); your web application communicates with Email Yak using a JSON (JavaScript Object Notation) API and HTTP callbacks (for push notification). The service is really easy to use and provides powerful features like email parsing and unlimited hosting of file attachements. To make it even easier to use, I tried to encapsulate the HTTP interactions in a simple ColdFusion component wrapper - EmailYak.cfc.


 
 
 

 
  
 
 
 

View the EmailYak.cfc project on my GitHub account.

The EmailYak.cfc project currently comes with a demonstration of the following features:

  • Register Domain
  • Register Email Address
  • Send Email
  • Send Email with Attachments
  • Get All Email
  • Get New Email
  • Get Email
  • Get Email List
  • Delete Email
  • Trigger Callback

The last feature, Trigger Callback, sends an email to the demo account (itself) in order to simulate a new email. Email Yak then parses the new email and pushes a notification out to the callback URL defined in the domain configuration.

Here's an example of one of the demo files that is making use of the EmailYak.cfc ColdFusion component. This sends an email with Base64-encoded attachments:

  • <!--- 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"
  • />

As you can see, the complexities of the HTTP request and the resource definition and the case-sensitivity has been hidden behind a simple sendEmail() method call.

I haven't started using this kind of workflow in production yet; but, I am itching for a chance to incorporate it. I love the idea of creating seamless interactions with my web application users in a way that removes as much friction as possible.




Reader Comments

Dec 14, 2011 at 2:47 PM // reply »
28 Comments

Nice. I'm going to try this out and see how it stacks up with mailgun and sendgrid. Thanks for the effort.

Have you been using GitHub all this time without telling me?


Dec 14, 2011 at 2:53 PM // reply »
11,246 Comments

@Aaron,

Ha ha, I've only starting using GitHub a bit. I really want to get into it a lot more. I still have a hand-written Git cheat-sheet next to my mouse pad so I can remember what some of the commands are. More so, however, I just like the idea of GitHub as a way to keep my code backed-up and also a place to keep open issues and what not.... you know, all the stuff that I'm probably *supposed* to be doing :D

Let me know what you think of Email Yak - it's the first thing I've tried (as you know). I'd be interested to hear how it compares to other things.


Dec 14, 2011 at 3:01 PM // reply »
28 Comments

I wonder if we should do a Git/GitHub deep dive one day. I'm in the same boat with sort of understanding it but it's still kind of an unknown.

Especially in the CF community where SVN is still tops, I'm guessing.

I've hijacked this thread enough. We can take it offline.


Dec 14, 2011 at 3:06 PM // reply »
11,246 Comments

@Aaron,

That would be awesome. I know only vaguely about the kinds of things that it can do.


Dec 14, 2011 at 3:58 PM // reply »
369 Comments

is GitHub some sort of versioning software or something?


Dec 14, 2011 at 4:41 PM // reply »
11,246 Comments

@Anna,

Yeah, it's live SVN, only different.


Dec 15, 2011 at 10:21 AM // reply »
369 Comments

Thanks, @Ben, it sounds like there are some differences, such as it has a way of executing scripts or something like that...and/or some sort of a shell, and some extra built-in functionality?


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 23, 2013 at 9:52 PM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Muhmmadibn Did you figure out a solution to launching PDFs? I am running into the same issues myself. There is no way to close the PDF or go back once you launch it. Thanks in advance! ... read »
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
May 23, 2013 at 4:26 PM
ColdFusion QueryAppend( qOne, qTwo )
@Heather, Glad people are still getting value out of this! ... read »
May 23, 2013 at 3:49 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, I meant the code at the bottom (not the video). I did try to experiment with an intermediary variable, like: value = users.id[ i ]; arrayContains( userIDs, value ); ... but t ... read »
May 23, 2013 at 11:06 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Are you talking about As Number: YES As String: YES As Java: YES? If so, that's with 3 different ways of referencing the constant 1, not users.id[1]. Query object references(*) are what seem ... read »
May 23, 2013 at 9:55 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dan, According to the CF Admin, I'm running Java "1.6.0_45". As far as the DB column, in the database it's an INT. I'll see if I can dig into what CF sees it as. @WebManWalking, But h ... read »
May 23, 2013 at 9:49 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, I think the problem is that we're used to loose typing in ColdFusion, like JavaScript. If a value is a number but it's needed in an expression to be a string, noooo problem. I've encountered ... read »
May 23, 2013 at 9:47 AM
ColdFusion QueryAppend( qOne, qTwo )
You rock! Thank you, thank you, thank you!!! ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools