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
240
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
56
Embrace the Grind
shrayasr
0
130
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
810
My journey with the world of Open Source
shrayasr
1
220
Introduction to SQLAlchemy ORMs
shrayasr
1
340
Intro to Mac OSX
shrayasr
2
220
Other Decks in Technology
See All in Technology
オートマトンと字句解析でRoslynを読む
tomokusaba
0
130
大 AI 時代におけるC# の事情 ~ぶっちゃけトークを交えながら~
nenonaninu
1
580
テックカンファレンス三大ステークホルダーの文化人類学 ─ 違いを認め合う関係性作り
bash0c7
5
1.4k
最高のシステムプロンプトを作るためにフィードバック機能を導入した話
alchemy1115
1
250
なぜ、あなたのエージェントは言うことを聞かないのか
segavvy
1
590
PLaMo 3.0 Primeの事後学習
pfn
PRO
0
210
AI研修(Day1)【MIXI 26新卒技術研修】
mixi_engineers
PRO
2
3k
AI Agent を本番環境へ―― Microsoft Foundry × Azure Serverless で作る Enterprise-Ready な基盤
shibayan
PRO
1
960
MCPをつなげて作る組織横断のAIエージェント基盤
tsubakimoto_s
0
470
DevOps Agentで運用判断をチーム資産にする~Agent InstructionsとAgent Skillを継続的に育てる~
fujioka6789
0
180
13年運用タイトルのサーバーサイドが辿り着いた現在地 ― モンスターストライクにおける技術・組織・AI活用から得た知見
mixi_engineers
PRO
1
360
AI工学特論: MLOps・継続的評価
asei
11
3.1k
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
230
Code Review Best Practice
trishagee
74
20k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
420
Documentation Writing (for coders)
carmenintech
77
5.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
New Earth Scene 8
popppiees
3
2.4k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
400
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