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

Input

Import libraries

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

Read the gsheet

1
spreadsheet_id = "1_VAF0kLPfnZxjA7HsF4F3YdZLi_V_wmZh0nHUP6DWPg"
2
data = 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']
4
specific_message_list = data['SPECIFIC MESSAGE']
Copied!

Model

Mail preview

1
url_image = naas.assets.add("2020.gif")
2
email_content = html.generate(
3
display='iframe',
4
title='🎅 Merry Christmas',
5
heading= '& Happy new year {first_name} 🍾',
6
image = f"{url_image}",
7
text_1= '{specific message}',
8
text_2= "Even if 2020 has been extremely difficult year, let's make 2021 better!",
9
text_3= "Keep smiling,",
10
text_4= "Keep laughing,",
11
text_5= "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]).replace("{specific message}",specific_message_list[i])
4
naas.notifications.send(email_to=email_list[i], subject=subject, html=content, email_from=your_email)
Copied!