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
220
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
86
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
130
A gentle introduction to types
shrayasr
1
130
The beauty that is PostgreSQL
shrayasr
2
320
Hylang - A Python powered Lisp AND a Lisp powered Python
shrayasr
2
700
My journey with the world of Open Source
shrayasr
1
200
Introduction to SQLAlchemy ORMs
shrayasr
1
260
Intro to Mac OSX
shrayasr
2
180
Android, A premiere
shrayasr
1
120
Other Decks in Technology
See All in Technology
AIコーディングの最前線 〜活用のコツと課題〜
pharma_x_tech
4
2.9k
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
220
ここはMCPの夜明けまえ
nwiizo
32
13k
MCPが変えるAIとの協働
knishioka
1
120
OpenLane-V2ベンチマークと代表的な手法
kzykmyzw
0
150
Новые мапы в Go. Вова Марунин, Clatch, МТС
lamodatech
0
1.5k
3D生成AIのための画像生成
kosukeito
2
580
「経験の点」の位置を意識したキャリア形成 / Career development with an awareness of the “point of experience” position
pauli
4
130
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
2
440
Cross Data Platforms Meetup LT 20250422
tarotaro0129
1
920
Gateway H2 モジュールで スマートホーム入門
minoruinachi
0
120
Pythonデータ分析実践試験 出題傾向や学習のポイントとテクニカルハイライト
terapyon
1
110
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The World Runs on Bad Software
bkeepers
PRO
68
11k
Agile that works and the tools we love
rasmusluckow
329
21k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.4k
Into the Great Unknown - MozCon
thekraken
38
1.7k
Building Applications with DynamoDB
mza
94
6.4k
Scaling GitHub
holman
459
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.7k
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.3k
GitHub's CSS Performance
jonrohan
1030
460k
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