Skip to content

Instantly share code, notes, and snippets.

@benschwarz
Created November 12, 2012 11:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benschwarz/4058977 to your computer and use it in GitHub Desktop.
Save benschwarz/4058977 to your computer and use it in GitHub Desktop.
Use postmarkapp.com and YQL to deliver email

Howto:

  • Run an insert statement to YQL, storing your API Key with a use statement linking to this gist.
insert into yql.storage.admin (value) values ("
use 'https://raw.github.com/gist/5ceb77a28686513f16a7/cb17fcb095847f320426fb0fc5261d47cf62b0d8/postmark.xml' as postmark;
set api_key='YOUR KEY HERE' on postmark;
")
  • This will return three store:// endpoints, copy the execute endpoint, go to the YQL console, remove any querystrings and replace it with ?env=store://your-store-uri

  • Run a query, like insert into postmark (from, to, subject, htmlbody) values (…)

You're the man now, dog.

<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Ben Schwarz</author>
<description>Deliver email using postmark</description>
<documentationURL>http://developer.postmarkapp.com/developer-build.html</documentationURL>
<sampleQuery>insert into {table} (from, to, subject, textbody) values (…) </sampleQuery>
</meta>
<bindings>
<insert itemPath="" produces="JSON">
<urls>
<url>https://api.postmarkapp.com/email</url>
</urls>
<inputs>
<key id="from" type="xs:string" paramType="variable" required="true" />
<key id="to" type="xs:string" paramType="variable" required="true" />
<key id="cc" type="xs:string" paramType="variable" required="false" />
<key id="bcc" type="xs:string" paramType="variable" required="false" />
<key id="subject" type="xs:string" paramType="variable" required="false" />
<key id="tag" type="xs:string" paramType="variable" required="false" />
<key id="htmlbody" type="xs:string" paramType="variable" required="false" />
<key id="textbody" type="xs:string" paramType="variable" required="false" />
<key id="replyto" type="xs:string" paramType="variable" required="false" />
<key id="api_key" type="xs:string" paramType="variable" required="true" />
</inputs>
<execute>
<![CDATA[
y.include('http://www.datatables.org/javascript/json2.js');
var content = {
"From": from,
"To": to,
"Cc": cc,
"Bcc": bcc,
"Subject": subject,
"Tag": tag,
"HtmlBody": htmlbody,
"TextBody": textbody,
"ReplyTo": replyto
}
response.object = request.header("Accept", "application/json").header("Content-Type", "application/json").header("X-Postmark-Server-Token", api_key).post( JSON.stringify( content ) ).response;
]]>
</execute>
</insert>
</bindings>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment