Read mailbox
Tags: #gmail #productivity #naas_drivers
Author: Martin Donadieu

Input

Import librairy

1
from naas_drivers import email
Copied!

Account credentials

1
username = "*********@gmail.com"
2
to = "*********@gmail.com"
3
password = "*********"
4
smtp_server = "imap.gmail.com"
5
box = "INBOX"
Copied!

Model

Connect to email box

1
emails = email.connect(username,
2
password,
3
username,
4
smtp_server)
Copied!

Get email list

1
df = emails.get(criteria="unseen")
2
df
Copied!
1
uid_list = df['uid'].tolist()
2
uid_list
Copied!

Setup the flags

1
%%time
2
uid = uid_list
3
flag = "DELETED"
4
# possible value for flag:
5
# flag = 'SEEN'
6
# flag = 'ANSWERED'
7
# flag = 'FLAGGED'
8
# flag = 'DELETED'
9
# flag = 'DRAFT'
10
# flag = 'RECENT'
Copied!

Output

Read mailbox

1
attachments = emails.set_flag(uid, flag, True)
Copied!
Copy link
Edit on GitHub