SlideShare a Scribd company logo
Email as a datasource for apps
Bruno Morency
    bruno@context.io
    @brunomorency
• Overview of the technologies
                  that make email

What this       • How your apps can fit in that
                  picture
presentation
will be about   • An intro to IMAP and message
                  bodies with common pitfalls.

                • Overview of Context.IO
“The reports of my death were
greatly exaggerated”
                      - Email
2.9 billion in 2010
3.8 billion by 2014
 180B messages/day
    340M 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”
Protocol for
SMTP   transmission of emails
       across the internet
Email as a datasource for applications
•   Message transport, nothing to
    do with content
•   Defines the envelope (sender
    and recipients)
•   Does not define the message
    headers
•   Chain from client to recipient’s
    server
DKIM   Standards for sender
       signatures and prevent
SPF    sender spoofing
Email as a datasource for applications
•   Complement spam filters
•   Opens the message and
    checks headers to decide if it
    will deliver it to the inbox
•   As a receiver, it’s one more
    way to block spam.
•   As a sender, it’s a tool you
    must master to avoid ending
    up in the spam folder
•   Email deliverability is an
    industry by itself
Protocol to allow a

IMAP   client to access and
       manipulate emails on a
       receiving server.
Email as a datasource for applications
•   All messages and their folder
    organization are on the server
•   Clients poll to know about with
    new messages that arrive or
    actions made through other
    clients
•   While it doesn’t send
    messages, clients usually
    store sent messages through it
Protocol to allow a
POP   client to retrieve emails
      from a receiving server.
Email as a datasource for applications
•   The server only serves as a
    temporary buffer for received
    messages
•   Classification and message
    state is purely a client-side
    concept
•   Many clients can access the
    same account but can’t
    coordinate anything
RFC-822     Standards defining
MIME        headers and the actual
            body of the message
Multipart
Where does your app fit in there?
Typical       1. Send emails to users

things apps   2. Receive emails from users
want to do
              3. Access emails users send and
with email       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
Email as a datasource for applications
Email as a datasource for applications
Email as a datasource for applications
Email as a datasource for applications
Email as a datasource for applications
Email as a datasource for applications
Introduction to IMAP
Me: “App Developer, meet IMAP. IMAP,
meet App Developer.”

IMAP: “I don’t give a sh*t about you, App
Developer. Go away!”
1. Connect to the IMAP server and authenticate

>"openssl"s_client"-crlf"-connect"imap.gmail.com:993
["a"few"lines"of"SSL"and"server"info"]
*"OK"Gimap"ready"for"requests"from"123.14.12.20"zw8i38638oab.180
a001"LOGIN"username"password
*"CAPABILITY"IMAP4rev1"UNSELECT"IDLE"NAMESPACE"QUOTA"ID"XLIST"CHILDREN"X-
GM-EXT-1"UIDPLUS"COMPRESS=DEFLATE
a001"OK"username"authenticated"(Success)
3. LIST mailboxes

a002"LIST"""""*"
*"LIST"(HasChildren)""/"""Drive"
*"LIST"(Noselect"HasChildren)""/"""Drive/Dev"
*"LIST"(HasNoChildren)""/"""Drive/Dev/A"
*"LIST"(HasNoChildren)""/"""Drive/Dev/B"
*"LIST"(HasNoChildren)""/"""INBOX"
*"LIST"(HasNoChildren)""/"""Archive"
*"LIST"(HasNoChildren)""/"""Sent"Mail"
*"LIST"(HasNoChildren)""/"""Drafts"
*"LIST"(HasNoChildren)""/"""Spam"
*"LIST"(HasChildren)""/"""My"folder"
*"LIST"(HasNoChildren)""/"""My"folder/label"A"
*"LIST"(HasNoChildren)""/"""My"folder/label"B"
a002"OK"Success
4. SELECT a mailbox

a003"SELECT""Drive/Dev"
*"FLAGS"(Answered"Flagged"Draft"Deleted"Seen)
*"OK"[PERMANENTFLAGS"(Deleted"Seen"*)]"Limited
*"OK"[UIDVALIDITY"614213447]"UIDs"valid
*"OK"[UIDNEXT"1042]"Predicted"next"UID
*"84"EXISTS
*"3"RECENT
a003"OK"[READ-WRITE]"Drive/Dev"selected."(Success)
4. FETCH messages

a013"FETCH"80:81"(FLAGS"BODY[HEADER.FIELDS"(DATE"FROM"SUBJECT)])
*"80"FETCH"(FLAGS"(Seen)"BODY[HEADER.FIELDS"(DATE"FROM"SUBJECT)]"{101}
Date:"Mon,"26"Jul"2012"14:05:16"-0400
From:"Dominik"Gehl"<dominik@gmail.com>
Subject:"test

)
*"81"FETCH"(FLAGS"(Seen)"BODY[HEADER.FIELDS"(DATE"FROM"SUBJECT)]"{115}
From:"Dominik"Gehl"<dominik@context.io>
Subject:"Payment"required"error
Date:"Tue,"27"Mar"2012"09:28:01"-0400

)
a013"OK"Success
4. FLAG a message as read

a015"STORE"81"+FLAGS"(Seen)
*"81"FETCH"(FLAGS"())
a015"OK"Success
4. CLOSE the mailbox and LOGOUT the account

a023"CLOSE
a023"OK"Returned"to"authenticated"state."(Success)
a024"LOGOUT
*"BYE"LOGOUT"Requested
a024"OK"LOGOUT"completed."(Success)
That didn’t seem so bad!
• There is no persistent primary
                key you can rely on to retrieve a
Pitfall #1:     message
Identifying
                • Message Sequence Number
messages
                • Unique Identifier
• Ascending and contiguous
             sequence. If the mailbox says
Sequence     11 exist, you can fetch
             messages with seq. nb. 1 to 11
Number
           • They can (and will) be
             reassigned during a session.
• 32-bit value uniquely identifying
              a message within a mailbox.

            • Ascending but not necessarily
Unique        incremental nor contiguous.

Identifier   • If you move a message to
(aka UID)     another mailbox, it will get a
              new UID in that new mailbox

            • Changes if the mailbox
              UIDVALIDITY changes
• Only the INBOX mailbox has a
                  special meaning.

Pitfall #2:     • Everything else has the
Special-use       meaning the client wants it to
                  have (which may not be in
folders (or       English)
lack thereof)   • Gmail has XLIST which add
                  mailbox attributes (Inbox, Sent,
                  Starred, ...)
Pitfall #3:     • Anything that searches or
                  fetches messages is done
No data until     within the context of a mailbox
you select a    • Can’t get account-wide list of
mailbox           messages
• It's an extension that isn't widely
Pitfall #4:     available and even then,
                restricted to a single mailbox
Threads
              • X-GM-THREAD-ID to the rescue
• You need to get and parse the
                body structure
Pitfall #5:
Attachment?   • As far as IMAP is concerned, an
                attachment is the same thing as
                any other MIME part
• Setting the Deleted flag marks
                the message for deletion but it’s
Pitfall #6:     still there

Deleting      • EXPUNGE will remove all
messages        messages with Deleted flag
                from the currently selected
                mailbox
• Purging client side message list
                 is a PITA.

Pitfall #7:    • Server won't tell you which
Keeping up       messages were deleted, you
                 just have to figure out some
with deleted     have been and find which one
messages         were.

               • It's the same if you want to keep
                 track of Seen flag.
Email as a datasource for applications
The joys of parsing email messages

Yé! 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:   • Great to track messages but
                spec says it's optional.
Message-ID
is optional    ... and it’s not always there.
• Refers to Message-ID of other
                emails
Pitfall #2:
In-Reply-To   • Very useful to rebuild threads

References      ... until an Outlook user jumps in and
                replaces it with their own Thread.
                Topic and Thread.Index headers
Pitfall #3:    • Content-Disposition tells you
Attachments      attachment or inline. Should
                 signature image be considered
are what you     as a file attachment?
decide them
               • TNEF attachments
to be
Email as a datasource for applications
webhooks




threads                                contacts




          messages              files
Demo of Context.IO console
Email as a datasource for applications

More Related Content

PDF
The Fundamental of Electronic Mail (E-mail)
PDF
Lecture 9 electronic_mail_representation_and_transfer
PPT
Electronic mail
PPT
How e-mail, chat, ATM, Skype, VOIP, online submission (online forms), online ...
PPTX
Electronic Mail
PPT
Mail services
DOCX
How email works
The Fundamental of Electronic Mail (E-mail)
Lecture 9 electronic_mail_representation_and_transfer
Electronic mail
How e-mail, chat, ATM, Skype, VOIP, online submission (online forms), online ...
Electronic Mail
Mail services
How email works

What's hot (20)

PPTX
Mail services and mail commands in linux
PDF
How Email Works
PPTX
Voice enable smtp client
PDF
Electronic mail
PPTX
Electronic mail
PPTX
Alternative Methods Of Communication To Consumer
PPTX
How e mail works
PPT
how email works
PPTX
Presentasi Bahasa Inggris " Email "
PPTX
Electronic mail - Computer Networks
PPTX
Electronic mail
PPT
About Web and E-mail
PPTX
Mail server using Linux(Ubuntu)
PPTX
Pop (post office protocol)e mail (electronic mail)
PPTX
Introduction to basics command in linux, and working in linux
PDF
Upload.gs
PDF
Final year project report on Internet And Interanet Emailing server
PPT
Mail services and mail commands in linux
How Email Works
Voice enable smtp client
Electronic mail
Electronic mail
Alternative Methods Of Communication To Consumer
How e mail works
how email works
Presentasi Bahasa Inggris " Email "
Electronic mail - Computer Networks
Electronic mail
About Web and E-mail
Mail server using Linux(Ubuntu)
Pop (post office protocol)e mail (electronic mail)
Introduction to basics command in linux, and working in linux
Upload.gs
Final year project report on Internet And Interanet Emailing server
Ad

Similar to Email as a datasource for applications (20)

PDF
Email As A Datasource
PPTX
Forensics Analysis of Email cyber forensics
PPTX
unit 5.pptxhhhnggjfvbjoohcchvvikbkbkbobh
PPTX
Electronic Mail.pptxElectronic Mail.pptx
PPT
Email transfer part 1
PPTX
window server 2008 mail configuration
PPTX
Email - electronic mail
PPTX
Email Forensics
PPTX
E mail Investigation
PPTX
WHAT IS OUTLOOK MAIL.pptx
PPTX
Simple mail transfer protocol
PPTX
Improving email reliability
PPTX
How to deploy Exchange Online Protection
PPTX
Application Layer Protocols in computer network.pptx
PPTX
CoLabora - Exchange Online Protection - June 2015
PPT
retrieving the mail
PPT
Mail server
PPT
Mail server
PPT
Ch22 system administration
PPTX
Computer networks unit v
Email As A Datasource
Forensics Analysis of Email cyber forensics
unit 5.pptxhhhnggjfvbjoohcchvvikbkbkbobh
Electronic Mail.pptxElectronic Mail.pptx
Email transfer part 1
window server 2008 mail configuration
Email - electronic mail
Email Forensics
E mail Investigation
WHAT IS OUTLOOK MAIL.pptx
Simple mail transfer protocol
Improving email reliability
How to deploy Exchange Online Protection
Application Layer Protocols in computer network.pptx
CoLabora - Exchange Online Protection - June 2015
retrieving the mail
Mail server
Mail server
Ch22 system administration
Computer networks unit v
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Big Data Technologies - Introduction.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Programs and apps: productivity, graphics, security and other tools
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
NewMind AI Weekly Chronicles - August'25 Week I
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation_ Review paper, used for researhc scholars
Mobile App Security Testing_ A Comprehensive Guide.pdf
MYSQL Presentation for SQL database connectivity
Big Data Technologies - Introduction.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks

Email as a datasource for applications