Send emails from Gsheet classic

Tags: #gmail #productivity #gsheet #naas_drivers #operations #snippet #email
Author: Jeremy Ravenel
Example : to a list of people in Gmail.


Import libraries

import naas_drivers
from naas_drivers import gsheet
from naas_drivers import html

Read the gsheet

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

Setting your email address

your_email = "[email protected]"
firstname_list = data['FIRST NAME']
email_list = data['EMAIL']


Mail preview

import naas
url_image = naas.assets.add("2020.gif")
email_content = naas_drivers.html.generate(
title='🎅 Merry Christmas',
heading= '& Happy new year {first_name} 🍾',
image = f"{url_image}",
text_1= "Even if 2020 has been extremely difficult year, let's make 2021 better!",
text_2= "Keep smiling,",
text_3= "Keep laughing,",
text_4= "Spread love ❤️",


Sending emails

for i in range(len(data)):
subject = "Merry Christmas & spread love for 2021 ❤️"
content = email_content.replace("{first_name}",firstname_list[i])
naas.notifications.send(email_to=email_list[i], subject=subject, html=content, email_from=your_email)