Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Python, Imap & Gmail
Search
Shrayas Rajagopal
April 25, 2015
Technology
270
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
67
Embrace the Grind
shrayasr
0
140
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
200
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
830
My journey with the world of Open Source
shrayasr
1
250
Introduction to SQLAlchemy ORMs
shrayasr
1
360
Intro to Mac OSX
shrayasr
2
220
Other Decks in Technology
See All in Technology
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
4
1.4k
Kiro Meetup #8 Kiro アップデート (2026/3/21〜2026/9/24)
katzueno
1
300
セルフサービスのオブザーバビリティ基盤をOpenTelemetryで作る / Building a Self-Service Observability Platform with OpenTelemetry
ymotongpoo
3
470
The kernel report
ennael
PRO
1
130
Harness Engineering on Rails
joelq
0
760
【ゲームメーカーズスクランブル2026】『Shadowverse: Worlds Beyond』UIとアニメーションで実現する最高のユーザー体験を叶えるプロトタイピング
cygames
PRO
1
700
Meet AgentCore Identity Consent Portal
hironobuiga
2
110
Lambda MicroVMsが分からなすぎたので使い所を1から考えてみた
tsukuboshi
1
230
Making AI Agents Safe and Fast- Jev, Obsidian, and the Meta-Harness
x5gtrn
PRO
0
160
IR Today: Theory, Practice, and Agents
dtunkelang
0
250
企業の現実世界をグラフで写し取る
sansantech
PRO
0
200
Account Factory for Terraformによる 標準化されたアカウント発行の自動化
pensuke628
0
120
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
750
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
840
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
290
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
290
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Believing is Seeing
oripsolob
1
230
So, you think you're a good person
axbom
PRO
2
2.2k
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