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
2
230
Python, Imap & Gmail
Shrayas Rajagopal
April 25, 2015
Tweet
Share
More Decks by Shrayas Rajagopal
See All by Shrayas Rajagopal
Embrace the Grind
shrayasr
0
100
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
150
A gentle introduction to types
shrayasr
1
140
The beauty that is PostgreSQL
shrayasr
2
330
Hylang - A Python powered Lisp AND a Lisp powered Python
shrayasr
2
740
My journey with the world of Open Source
shrayasr
1
200
Introduction to SQLAlchemy ORMs
shrayasr
1
280
Intro to Mac OSX
shrayasr
2
180
Android, A premiere
shrayasr
1
130
Other Decks in Technology
See All in Technology
ZOZOTOWNフロントエンドにおけるディレクトリの分割戦略
zozotech
PRO
18
5.4k
見てわかるテスト駆動開発
recruitengineers
PRO
5
380
我々は雰囲気で仕事をしている / How can we do vibe coding as well
naospon
2
220
小さなチーム 大きな仕事 - 個人開発でAIをフル活用する
himaratsu
0
120
Go で言うところのアレは TypeScript で言うとコレ / Kyoto.なんか #7
susisu
7
1.8k
Devinを使ったモバイルアプリ開発 / Mobile app development with Devin
yanzm
0
190
実践データベース設計 ①データベース設計概論
recruitengineers
PRO
3
270
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
2
20k
Claude Code x Androidアプリ 開発
kgmyshin
1
590
Preferred Networks (PFN) とLLM Post-Training チームの紹介 / 第4回 関東Kaggler会 スポンサーセッション
pfn
PRO
1
230
新卒(ほぼ)専業Kagglerという選択肢
nocchi1
1
2.4k
TypeScript入門
recruitengineers
PRO
20
6.8k
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.6k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
283
13k
Rails Girls Zürich Keynote
gr2m
95
14k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Become a Pro
speakerdeck
PRO
29
5.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
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