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
240
2
Share
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
45
Embrace the Grind
shrayasr
0
130
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
180
A gentle introduction to types
shrayasr
1
180
The beauty that is PostgreSQL
shrayasr
2
340
Hylang - A Python powered Lisp AND a Lisp powered Python
shrayasr
2
800
My journey with the world of Open Source
shrayasr
1
220
Introduction to SQLAlchemy ORMs
shrayasr
1
330
Intro to Mac OSX
shrayasr
2
210
Other Decks in Technology
See All in Technology
JICUG あなたのAI駆動開発パートナー IBM Bob を使ったアプリ開発
1ftseabass
PRO
0
120
Java正規表現エンジン(NFA)の仕組みと パフォーマンスを維持するための最適化手法
takeuchi_132917
0
140
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
1
240
開発を止めない CI/CD ~CI Visibilityによる継続的最適化~
pensuke628
0
160
AIが変えた"品質の守り方"
kkakizaki
13
5.2k
20260528_生成AIを専属DSに_Howの次にすべきことを考える
doradora09
PRO
0
240
LLM時代のリファクタリング戦略_AIエージェントによる段階的・安全なTS移行方法
play_inc
0
430
大規模災害時でも高い信頼性を維持するアプリケーション基盤の実現/nikkei-tech-talk46
nikkei_engineer_recruiting
0
110
Gradle×GitHub_ActionsでCI時間を約50%短縮 ジョブ分割の設計と落とし穴 / Cutting CI Time by ~50% with Gradle and GitHub Actions: Job-Splitting Design and Pitfalls
takatty
0
510
はじめてのAI-DLC
yoshidashingo
2
610
Anthropic AIネイティブ・スタートアップ構築のプレイブック を理解する
nagatsu
0
210
テストコードのないプロジェクトにテストを根付かせる
tttol
0
220
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
How to Ace a Technical Interview
jacobian
281
24k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Design in an AI World
tapps
1
220
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
200
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
ラッコキーワード サービス紹介資料
rakko
1
3.4M
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
130
Scaling GitHub
holman
464
140k
GitHub's CSS Performance
jonrohan
1033
470k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
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