Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Python, Imap & Gmail
Search
Shrayas Rajagopal
April 25, 2015
Technology
260
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Python, Imap & Gmail
Shrayas Rajagopal
April 25, 2015
More Decks by Shrayas Rajagopal
See All by Shrayas Rajagopal
Know Thy Packets - PyCon India 2025
shrayasr
0
63
Embrace the Grind
shrayasr
0
140
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
190
A gentle introduction to types
shrayasr
1
200
The beauty that is PostgreSQL
shrayasr
2
350
Hylang - A Python powered Lisp AND a Lisp powered Python
shrayasr
2
820
My journey with the world of Open Source
shrayasr
1
250
Introduction to SQLAlchemy ORMs
shrayasr
1
350
Intro to Mac OSX
shrayasr
2
220
Other Decks in Technology
See All in Technology
Hub & Spoke 環境のネットワークルーティングを分解してみる
tsuyataku
1
520
AIとペアプロを始める。人とのペアプロをやめる。ペアプロの良さを改めて知る。もっと好きになった。 / Rediscovering Pair Programming
honyanya
1
200
少人数データチームのDevin活用実践事例
runandy16
2
430
IDperturb: Enhancing Variation in Synthetic Face Generation via Angular Perturbation
sansantech
PRO
0
140
Jetpack Compose で挑む新聞紙面UI ─ 複合ジェスチャー・ポリゴン記事領域・適応的ページ構成という3つの壁/droidkaigi2026
nikkei_engineer_recruiting
0
190
JAWS-UG初心者支部#88わいわい初心塾(夏休みの宿題やったかGit編)
otsuki
0
120
20260906 「AWS運用入門」著者が教える、運用業務への生成AI活用入門
masaruogura
0
220
生成AI時代の クレデンシャルとパーミッション設計
nrinetcom
PRO
3
1.5k
AI時代に、プロダクトの数だけ積み上がる所有コストをどうエンジニアリングするか / Engineering the Cost of Ownership
kzkmaeda
0
970
データエンジニアの困りごとをDevinと一緒に解消する
10xinc
2
800
振り返りこそエンジニアの本領
negima
0
270
データエンジニアリングワークショップ:Auto LoaderとSparkで学ぶデータパイプライン構築
databricksjapan
PRO
0
150
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Docker and Python
trallard
47
4.2k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
GraphQLとの向き合い方2022年版
quramy
50
15k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Design in an AI World
tapps
1
300
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
360
What's in a price? How to price your products and services
michaelherold
247
13k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Raft: Consensus for Rubyists
vanstee
141
7.7k
Transcript
Chennaipy APRIL 2015
Python Imap & Gmail
@shrayasr Logic Soft
Email
Email
Email
Email POP3
Email POP3 IMAP
POP3 Post Office Protocol
SIMPLE POP3 Post Office Protocol
SIMPLE ONE MAILBOX POP3 Post Office Protocol
SIMPLE SSL/TLS ONE MAILBOX POP3 Post Office Protocol
SIMPLE SSL/TLS ONE MAILBOX MOVE POP3 Post Office Protocol
SIMPLE SSL/TLS ONE MAILBOX MOVE ALL PARTS POP3 Post Office
Protocol
IMAP Internet Msg Access Protocol
IMAP Internet Msg Access Protocol ASYNC
IMAP Internet Msg Access Protocol ASYNC MAILBOXes
IMAP Internet Msg Access Protocol ASYNC CLIENTS MAILBOXes
IMAP Internet Msg Access Protocol ASYNC CLIENTS MAILBOXes SEARCHES
IMAP Internet Msg Access Protocol ASYNC CLIENTS MAILBOXes SEARCHES EXTENSIONS
Gmail @gmail.com
Settings > Forwarding and POP/IMAP /settings/security/lesssecureapps Requirements
Python
>>> import imaplib
>>> import imaplib Standard Library
CASES
Check the count of mails in my INBOX 1
email_count.py import imaplib client = IMAP4_SSL("imap.gmail.com", "993") client.login("
[email protected]
","barfoo") result, response
= client.select("INBOX") if result == "OK": print "count is %s" % response[0]
Gmail Handling folders
Folders
Folders
Folders
“[Gmail]/” Prefix
[Gmail]/Spam SPAM
[Gmail]/Drafts DRAFTS
Gmail IMAP &
Gmail IMAP
Gmail IMAP EXT ENSIONS!
Gmail IMAP EXTENSIONS!
Mails sent to Vijay from 11 Apr to date 2
to: (<email>) after:<date> before: <date>
?
SEARCH IMAP
SEARCH X-‐GM-‐RAW IMAP Gmail
Mails sent to Vijay from 11 Apr to date 2
# ... client.select("[Gmail]/Sent Mail") client.search(None, '(X-GM-RAW "to: (
[email protected]
) after:2015/4/11 before:2015/4/26")')
# ... advanced_search.py
# ... client.select("[Gmail]/Sent Mail") client.search(None, '(AND (TO "
[email protected]
") (FROM "
[email protected]
"))')
# ... imap_search.py
Add label “Foo” to all mails sent to me from
[email protected]
3
STORE IMAP
STORE X-‐GM-‐LABELS IMAP Gmail
# ... client.select("INBOX") emails = client.search(None, '(FROM "
[email protected]
")') for email
in emails[1][0].split(): client.store(email, '+X-GM-LABELS', "foo") # ... add_foo_label.py
RECAP
• IMAP, POP3
• IMAP, POP3 • imaplib
• IMAP, POP3 • imaplib • Gmail IMAP extensions
X-‐GM-‐RAW, X-‐GM-‐LABELS
/Fin @shrayasr