Links

Send emails from Gsheet specific

Tags: #gmail #productivity #gsheet #naas_drivers #operations #snippet #email
Author: Jeremy Ravenel
Description: This notebook allows users to send emails from a Google Sheet with Gmail.

Input

Import libraries

import naas
from naas_drivers import gsheet
from naas_drivers import html

Read the gsheet

spreadsheet_id = "1_VAF0kLPfnZxjA7HsF4F3YdZLi_V_wmZh0nHUP6DWPg"
data = 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"]
specific_message_list = data["SPECIFIC MESSAGE"]

Model

Mail preview

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

Output

Sending emails

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