Send emails from Gsheet classic
Tags: #gmail #productivity #gsheet #naas_drivers
Author: Jeremy Ravenel
Example : to a list of people in Gmail.

Input

Import libraries

1
import naas_drivers
2
from naas_drivers import gsheet
3
from naas_drivers import html
Copied!

Read the gsheet

1
spreadsheet_id = "1swGTMX6d_N8-AVRueBEd8C0J6OlvO218iDSVMootWZk"
2
data = naas_drivers.gsheet.connect(spreadsheet_id).get(sheet_name="Sheet1")
Copied!

Setting your email address

1
your_email = "[email protected]"
2
firstname_list = data['FIRST NAME']
3
email_list = data['EMAIL']
Copied!

Model

Mail preview

1
import naas
2
url_image = naas.assets.add("2020.gif")
3
email_content = naas_drivers.html.generate(
4
display='iframe',
5
title='🎅 Merry Christmas',
6
heading= '& Happy new year {first_name} 🍾',
7
image = f"{url_image}",
8
text_1= "Even if 2020 has been extremely difficult year, let's make 2021 better!",
9
text_2= "Keep smiling,",
10
text_3= "Keep laughing,",
11
text_4= "Spread love ❤️",
12
13
)
Copied!

Output

Sending emails

1
for i in range(len(data)):
2
subject = "Merry Christmas & spread love for 2021 ❤️"
3
content = email_content.replace("{first_name}",firstname_list[i])
4
naas.notifications.send(email_to=email_list[i], subject=subject, html=content, email_from=your_email)
Copied!
Last modified 2mo ago
Copy link
Edit on GitHub