Links

Read mailbox

Tags: #gmail #productivity #naas_drivers #operations #snippet #dataframe
Author: Martin Donadieu​

Input

Import librairy

from naas_drivers import email

Account credentials

username = "*********@gmail.com"
to = "*********@gmail.com"
password = "*********"
smtp_server = "imap.gmail.com"
box = "INBOX"

Model

Connect to email box

emails = email.connect(username,
password,
username,
smtp_server)

Get email list

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

Setup the flags

%%time
uid = uid_list
flag = "DELETED"
# possible value for flag:
# flag = 'SEEN'
# flag = 'ANSWERED'
# flag = 'FLAGGED'
# flag = 'DELETED'
# flag = 'DRAFT'
# flag = 'RECENT'

Output

Read mailbox

attachments = emails.set_flag(uid, flag, True)