Email as a datasource for apps 
Tony Blank 
tony@context.io 
@thetonyblank
“The reports of my death 
were greatly exaggerated” 
- Email
4.93 .b9 ibllililoionn ibny 2 0210317 
183B messages/day 
400M tweets/day
group collaboration 
task management 
document collaboration 
customer support 
app notification 
Email is a communications system 
! 
project management 
client relationship 
applicant tracking 
photo sharing 
bug tracking 
Nigerian extortion
Overview of protocols and standards 
or “which acronym does what”
SMTP Protocol for 
transmission of emails 
across the internet
IMAP 
Protocol to allow a 
client to access and 
manipulate emails on a 
receiving server.
• All messages and their folder 
organization are on the server 
• Clients poll to know about new 
messages that arrive or 
actions made through other 
clients 
• While it doesn’t send 
messages, clients usually 
store sent messages through it
POP Protocol to allow a 
client to retrieve emails 
from a receiving server.
RFC-822 
MIME 
Multipart 
Standards defining 
headers and the actual 
body of the message
Where does your app fit in there?
Typical 
things apps 
want to do 
with email 
1. Send emails to users 
2. Receive emails from users 
3. Access emails users send and 
receive.
group collaboration 
task management 
document collaboration 
customer support 
app notification 
Email is a communications system 
! 
project management 
client relationship 
applicant tracking 
photo sharing 
bug tracking 
Nigerian extortion
Introduction to IMAP
Me: “App Developer, meet IMAP. IMAP, 
meet App Developer.” 
! 
IMAP: “I don’t give a shit about you, App 
Developer. Go away!”
Pitfall #1: Identifying messages
Sequence Number
Unique Identifier 
(aka UID)
Pitfall #2: 
No data until you 
select a mailbox
Pitfall #3: 
Attachments
Pitfall #4: 
Deleting messages
The joys of parsing email messages 
Yo! I fetched a message! Now what do I do?
A simple message 
Delivered-­‐To: 
sysadmin@context.io 
Return-­‐Path: 
<2012050639be@bounces.amazon.com> 
Received: 
by 
10.229.135.136 
with 
SMTP 
id 
n8mr410292qct.135.1336583200550; 
Wed, 
09 
May 
2012 
10:06:40 
-­‐0700 
(PDT) 
Received: 
from 
smtp-­‐out.amazon.com 
(smtp-­‐out.amazon.com. 
[72.21.212.39]) 
by 
mx.google.com 
with 
ESMTP 
id 
b2si1383913qcd.195.2012.05.06.40; 
Wed, 
09 
May 
2012 
10:06:40 
-­‐0700 
(PDT) 
Date: 
Wed, 
9 
May 
2012 
17:06:39 
+0000 
(UTC) 
From: 
Amazon 
EC2 
Notification 
<no-­‐reply-­‐aws@amazon.com> 
To: 
"Sys 
Admin" 
<sys@context.io> 
Cc: 
"Alerts" 
<alerts@context.io> 
Message-­‐ID: 
<urn.correios.msg.2012050639be@1336583199032.us-­‐1.amazon.com> 
Subject: 
Notice: 
Amazon 
EC2 
Instance 
scheduled 
for 
retirement 
MIME-­‐Version: 
1.0 
Content-­‐Type: 
text/plain; 
charset=UTF-­‐8 
Content-­‐Transfer-­‐Encoding: 
7bit 
! 
Hello, 
...
A message with an attachment 
MIME-­‐Version: 
1.0 
Content-­‐Type: 
multipart/mixed; 
boundary=_MYBOUNDARY_ 
! 
-­‐-­‐_MYBOUNDARY_ 
Content-­‐Type: 
text/plain 
! 
This 
is 
the 
body 
of 
the 
message. 
-­‐-­‐_MYBOUNDARY_ 
Content-­‐Type: 
image/jpeg; 
name="IMG_713.jpg" 
Content-­‐Disposition: 
attachment; 
filename="IMG_713.jpg"; 
size=6379099; 
Content-­‐Transfer-­‐Encoding: 
base64 
! 
/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAZA+4AJkFkb2JlAGTAAAAAAQMA 
AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD8IAEQgAegG1AwERAI 
RAQMRAfEASMAAQACAwEBAQEBAAAAAAAAAAAHCAUGCQQDAgEKAQEAAgIDAQAAAAAAAAAAAAAAB 
gcFCAEDBAIQAAEEAgEBBgQGAQUAAAAAAAUCAwQGAQcAEjBQERMUFRBgFhcgQHAhNAhBMSIjJD 
URAAIC== 
-­‐-­‐_MYBOUNDARY_-­‐-­‐
A message with alternative parts 
MIME-­‐Version: 
1.0 
Content-­‐Type: 
multipart/alternative; 
boundary=_MYBOUNDARY_ 
! 
-­‐-­‐_MYBOUNDARY_ 
Content-­‐Type: 
text/plain; 
charset="us-­‐ascii" 
Content-­‐Transfer-­‐Encoding: 
quoted-­‐printable 
! 
Hello! 
Here’s 
a 
message 
with 
*rich* 
text 
-­‐-­‐_MYBOUNDARY_ 
Content-­‐Type: 
text/html; 
charset="us-­‐ascii" 
Content-­‐Transfer-­‐Encoding: 
quoted-­‐printable 
! 
<html><body>Hello! 
Here’s 
a 
message 
with 
<b>rich</b> 
text</body></html> 
-­‐-­‐_MYBOUNDARY_-­‐-­‐
Pitfall #1: 
Message-ID is optional
Pitfall #2: 
In-Reply-To References
Pitfall #3: 
Attachments are what you 
decide them to be
contacts 
messages files 
threads 
webhooks
Email as a datasource for apps 
Tony Blank 
tony@context.io 
@thetonyblank

Email As A Datasource

  • 1.
    Email as adatasource for apps Tony Blank tony@context.io @thetonyblank
  • 2.
    “The reports ofmy death were greatly exaggerated” - Email
  • 3.
    4.93 .b9 ibllililoionnibny 2 0210317 183B messages/day 400M tweets/day
  • 4.
    group collaboration taskmanagement document collaboration customer support app notification Email is a communications system ! project management client relationship applicant tracking photo sharing bug tracking Nigerian extortion
  • 5.
    Overview of protocolsand standards or “which acronym does what”
  • 6.
    SMTP Protocol for transmission of emails across the internet
  • 7.
    IMAP Protocol toallow a client to access and manipulate emails on a receiving server.
  • 8.
    • All messagesand their folder organization are on the server • Clients poll to know about new messages that arrive or actions made through other clients • While it doesn’t send messages, clients usually store sent messages through it
  • 9.
    POP Protocol toallow a client to retrieve emails from a receiving server.
  • 10.
    RFC-822 MIME Multipart Standards defining headers and the actual body of the message
  • 11.
    Where does yourapp fit in there?
  • 12.
    Typical things apps want to do with email 1. Send emails to users 2. Receive emails from users 3. Access emails users send and receive.
  • 13.
    group collaboration taskmanagement document collaboration customer support app notification Email is a communications system ! project management client relationship applicant tracking photo sharing bug tracking Nigerian extortion
  • 20.
  • 21.
    Me: “App Developer,meet IMAP. IMAP, meet App Developer.” ! IMAP: “I don’t give a shit about you, App Developer. Go away!”
  • 22.
  • 23.
  • 24.
  • 25.
    Pitfall #2: Nodata until you select a mailbox
  • 26.
  • 27.
  • 29.
    The joys ofparsing email messages Yo! I fetched a message! Now what do I do?
  • 30.
    A simple message Delivered-­‐To: sysadmin@context.io Return-­‐Path: <2012050639be@bounces.amazon.com> Received: by 10.229.135.136 with SMTP id n8mr410292qct.135.1336583200550; Wed, 09 May 2012 10:06:40 -­‐0700 (PDT) Received: from smtp-­‐out.amazon.com (smtp-­‐out.amazon.com. [72.21.212.39]) by mx.google.com with ESMTP id b2si1383913qcd.195.2012.05.06.40; Wed, 09 May 2012 10:06:40 -­‐0700 (PDT) Date: Wed, 9 May 2012 17:06:39 +0000 (UTC) From: Amazon EC2 Notification <no-­‐reply-­‐aws@amazon.com> To: "Sys Admin" <sys@context.io> Cc: "Alerts" <alerts@context.io> Message-­‐ID: <urn.correios.msg.2012050639be@1336583199032.us-­‐1.amazon.com> Subject: Notice: Amazon EC2 Instance scheduled for retirement MIME-­‐Version: 1.0 Content-­‐Type: text/plain; charset=UTF-­‐8 Content-­‐Transfer-­‐Encoding: 7bit ! Hello, ...
  • 31.
    A message withan attachment MIME-­‐Version: 1.0 Content-­‐Type: multipart/mixed; boundary=_MYBOUNDARY_ ! -­‐-­‐_MYBOUNDARY_ Content-­‐Type: text/plain ! This is the body of the message. -­‐-­‐_MYBOUNDARY_ Content-­‐Type: image/jpeg; name="IMG_713.jpg" Content-­‐Disposition: attachment; filename="IMG_713.jpg"; size=6379099; Content-­‐Transfer-­‐Encoding: base64 ! /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAZA+4AJkFkb2JlAGTAAAAAAQMA AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD8IAEQgAegG1AwERAI RAQMRAfEASMAAQACAwEBAQEBAAAAAAAAAAAHCAUGCQQDAgEKAQEAAgIDAQAAAAAAAAAAAAAAB gcFCAEDBAIQAAEEAgEBBgQGAQUAAAAAAAUCAwQGAQcAEjBQERMUFRBgFhcgQHAhNAhBMSIjJD URAAIC== -­‐-­‐_MYBOUNDARY_-­‐-­‐
  • 32.
    A message withalternative parts MIME-­‐Version: 1.0 Content-­‐Type: multipart/alternative; boundary=_MYBOUNDARY_ ! -­‐-­‐_MYBOUNDARY_ Content-­‐Type: text/plain; charset="us-­‐ascii" Content-­‐Transfer-­‐Encoding: quoted-­‐printable ! Hello! Here’s a message with *rich* text -­‐-­‐_MYBOUNDARY_ Content-­‐Type: text/html; charset="us-­‐ascii" Content-­‐Transfer-­‐Encoding: quoted-­‐printable ! <html><body>Hello! Here’s a message with <b>rich</b> text</body></html> -­‐-­‐_MYBOUNDARY_-­‐-­‐
  • 33.
  • 34.
  • 35.
    Pitfall #3: Attachmentsare what you decide them to be
  • 38.
    contacts messages files threads webhooks
  • 39.
    Email as adatasource for apps Tony Blank tony@context.io @thetonyblank