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
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
40
Embrace the Grind
shrayasr
0
120
The programmers guide to timestamps and timezones - PyCon India 2023
shrayasr
0
170
A gentle introduction to types
shrayasr
1
170
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
210
Introduction to SQLAlchemy ORMs
shrayasr
1
320
Intro to Mac OSX
shrayasr
2
200
Other Decks in Technology
See All in Technology
不確実性と戦いながら見積もりを作成するプロセス/mitsumori-process
hirodragon112
1
170
OpenClaw初心者向けセミナー / OpenClaw Beginner Seminar
cmhiranofumio
0
170
Oracle Cloud Infrastructure:2026年3月度サービス・アップデート
oracle4engineer
PRO
0
300
TUNA Camp 2026 京都Stage ヒューリスティックアルゴリズム入門
terryu16
0
650
AIエージェント時代に必要な オペレーションマネージャーのロールとは
kentarofujii
0
270
「できない」のアウトプット 同人誌『精神を壊してからの』シリーズ出版を 通して得られたこと
comi190327
3
520
Zephyr(RTOS)でOpenPLCを実装してみた
iotengineer22
0
180
40代からのアウトプット ― 経験は価値ある学びに変わる / 20260404 Naoki Takahashi
shift_evolve
PRO
4
700
Even G2 クイックスタートガイド(日本語版)
vrshinobi1
0
190
Bref でサービスを運用している話
sgash708
0
220
FASTでAIエージェントを作りまくろう!
yukiogawa
4
180
AWSで2番目にリリースされたサービスについてお話しします(諸説あります)
yama3133
0
110
Featured
See All Featured
The Limits of Empathy - UXLibs8
cassininazir
1
280
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
53k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Thoughts on Productivity
jonyablonski
76
5.1k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Code Reviewing Like a Champion
maltzj
528
40k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
120
The Cost Of JavaScript in 2023
addyosmani
55
9.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