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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Shrayas Rajagopal
April 25, 2015
Technology
2
230
Python, Imap & Gmail
Shrayas Rajagopal
April 25, 2015
Tweet
Share
More Decks by Shrayas Rajagopal
See All by Shrayas Rajagopal
Know Thy Packets - PyCon India 2025
shrayasr
0
36
Embrace the Grind
shrayasr
0
120
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
160
A gentle introduction to types
shrayasr
1
170
The beauty that is PostgreSQL
shrayasr
2
330
Hylang - A Python powered Lisp AND a Lisp powered Python
shrayasr
2
800
My journey with the world of Open Source
shrayasr
1
210
Introduction to SQLAlchemy ORMs
shrayasr
1
310
Intro to Mac OSX
shrayasr
2
190
Other Decks in Technology
See All in Technology
GitLab Duo Agent Platform × AGENTS.md で実現するSpec-Driven Development / GitLab Duo Agent Platform × AGENTS.md
n11sh1
0
130
Amazon S3 Vectorsを使って資格勉強用AIエージェントを構築してみた
usanchuu
3
450
SREじゃなかった僕らがenablingを通じて「SRE実践者」になるまでのリアル / SRE Kaigi 2026
aeonpeople
6
2.3k
OpenShiftでllm-dを動かそう!
jpishikawa
0
100
レガシー共有バッチ基盤への挑戦 - SREドリブンなリアーキテクチャリングの取り組み
tatsukoni
0
210
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
460
Red Hat OpenStack Services on OpenShift
tamemiya
0
100
生成AI時代にこそ求められるSRE / SRE for Gen AI era
ymotongpoo
5
3.1k
仕様書駆動AI開発の実践: Issue→Skill→PRテンプレで 再現性を作る
knishioka
2
640
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
240
Context Engineeringの取り組み
nutslove
0
340
予期せぬコストの急増を障害のように扱う――「コスト版ポストモーテム」の導入とその後の改善
muziyoshiz
1
1.8k
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Automating Front-end Workflow
addyosmani
1371
200k
How to make the Groovebox
asonas
2
1.9k
Everyday Curiosity
cassininazir
0
130
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
99
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
200
Music & Morning Musume
bryan
47
7.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
110
Discover your Explorer Soul
emna__ayadi
2
1.1k
Thoughts on Productivity
jonyablonski
74
5k
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