Mailbox
Interact with mailbox thanks to Naas utility driver.
Don't feel like reading the doc πŸ˜… ? Get started with this 3min video.

Connect

You can save your connection and don't repeat it for each method.
1
username = "USERNAME"
2
password = "PASSWORD"
3
email_from = "[email protected]",
4
smtp_server = "smtp.sendgrid.net",
5
smtp_port = 465,
6
smtp_type = "SSL",
7
​
8
emails = naas_drivers.email.connect(username,
9
password,
10
email_from,
11
smtp_server,
12
smtp_port,
13
smtp_type)
Copied!

Send

Text

Send an email to anyone, notify about data changes, alert on notebooks operations, etc...
2
subject = "The tesla action is going up"
3
content = "check in the link the chart data maide from fresh dataset : [LINK]"
4
​
5
emails.send(email_to=email, subject=subject, html=content)
Copied!

File

2
subject = "The tesla action is going up"
3
content = "check in the link the chart data maide from fresh dataset : [LINK]"'
4
files = ["path/to/my/super/data.csv"]
5
​
6
emails.send(email_to=email, subject=subject, html=content, files=files)
Copied!

HTML

2
subject = "The tesla action is going up"
3
image_path = "path/to/my/super/data.png"
4
html = f"<h1>Check in the link the chart image below</h1><br/> <img src="{image_path}"/>"
5
​
6
emails.send(email_to=email, subject=subject, html=content)
Copied!

Get

1
email_df = emails.get()
Copied!

Get from folder

1
box = "INBOX" # check the list you have with get_mailbox
2
email_df = emails.get(box)
Copied!

Get mailbox list

1
mailboxs = emails.get_mailbox()
Copied!

Subfolder

1
main_folder = "INBOX"
2
mailboxs = emails.get_mailbox(main_folder)
Copied!

Folder

List

1
uid = "4460"
2
box = "ALL"
3
folders = emails.get_mailbox(box)
Copied!

Status

1
uid = "4460"
2
box = "INBOX"
3
status = emails.status(box)
Copied!

Seen

1
uid = "4460"
2
emails.set_seen(uid, True)
Copied!

Flags

1
uid = "4460"
2
flag = "ANSWERED"
3
# possible value for flag:
4
# flag = 'SEEN'
5
# flag = 'ANSWERED'
6
# flag = 'FLAGGED'
7
# flag = 'DELETED'
8
# flag = 'DRAFT'
9
# flag = 'RECENT'
10
attachments = emails.set_flag(uid, flag, True)
Copied!