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
210
Python, Imap & Gmail
Shrayas Rajagopal
April 25, 2015
Tweet
Share
More Decks by Shrayas Rajagopal
See All by Shrayas Rajagopal
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
84
A gentle introduction to types
shrayasr
1
130
The beauty that is PostgreSQL
shrayasr
2
310
Hylang - A Python powered Lisp AND a Lisp powered Python
shrayasr
2
580
My journey with the world of Open Source
shrayasr
1
190
Introduction to SQLAlchemy ORMs
shrayasr
1
250
Intro to Mac OSX
shrayasr
2
160
Android, A premiere
shrayasr
1
110
SeeQuaL
shrayasr
1
150
Other Decks in Technology
See All in Technology
自己改善からチームを動かす! 「セルフエンジニアリングマネージャー」のすゝめ
shoota
6
840
私が trocco を推す理由
__allllllllez__
1
260
require(ESM)とECMAScript仕様
uhyo
3
820
ゼロから始めるVue.jsコミュニティ貢献 / first-vuejs-community-contribution-link-and-motivation
lmi
1
130
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
1
540
開発生産性大幅アップ!Postman VS Code拡張機能
nagix
2
440
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
1
250
生産性向上チームの紹介
cybozuinsideout
PRO
1
880
R3のコードから見る実践LINQ実装最適化・コンカレントプログラミング実例
neuecc
2
390
IaCジェネレーターとBedrockで詳細設計書を生成してみた
tsukasa_ishimaru
3
350
Google Cloud Next '24 Recap(Cloud Run/k8s)
mokocm
0
250
Cypress or Playwright?
rainerhahnekamp
0
130
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
17
6.4k
Six Lessons from altMBA
skipperchong
21
3k
The Pragmatic Product Professional
lauravandoore
25
5.8k
A better future with KSS
kneath
231
16k
Rails Girls Zürich Keynote
gr2m
91
13k
The Power of CSS Pseudo Elements
geoffreycrofte
60
5k
Designing on Purpose - Digital PM Summit 2013
jponch
110
6.5k
The Cost Of JavaScript in 2023
addyosmani
16
3.9k
Design by the Numbers
sachag
274
18k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
6
1.5k
Gamification - CAS2011
davidbonilla
76
4.6k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
21
1.6k
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