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
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
59
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
190
The beauty that is PostgreSQL
shrayasr
2
340
Hylang - A Python powered Lisp AND a Lisp powered Python
shrayasr
2
820
My journey with the world of Open Source
shrayasr
1
240
Introduction to SQLAlchemy ORMs
shrayasr
1
350
Intro to Mac OSX
shrayasr
2
220
Other Decks in Technology
See All in Technology
オートロックマンションなのに、各部屋は施錠なし!? 攻撃者が組織内ネットワークで大暴れする理由 / The Front Door Is Locked, but the Rooms Are Wide Open: Why Attackers Move Freely Inside Enterprise Networks
nttcom
1
6k
モダンフロントエンド 開発研修
recruitengineers
PRO
4
670
FDEの心得
noriakioji
5
6.1k
AI-DLC実践録_フルサイクル開発への挑戦
miyuc
0
150
TypeScript入門 2026
recruitengineers
PRO
3
600
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」紹介資料
laysakura
2
9k
QAエンジニア起点で進める、SmartHRにおける信頼性向上について
kaomi_wombat
1
140
Digitization部 紹介資料
sansan33
PRO
2
7.7k
ホームラボ紹介
y_sera15
0
190
Head First モブプログラミング / Head First Mobprogramming
takaking22
10
12k
PLATEAU で バーチャル花火大会
tatsuya1970
0
160
Flutterをカメラで動かしたかった話
sony
1
140
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
What's in a price? How to price your products and services
michaelherold
247
13k
WCS-LA-2024
lcolladotor
0
800
Statistics for Hackers
jakevdp
799
230k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
GitHub's CSS Performance
jonrohan
1033
470k
Automating Front-end Workflow
addyosmani
1369
210k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
770
Designing Powerful Visuals for Engaging Learning
tmiket
1
490
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
790
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
270
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