How to Use Google Sheets and Apps Script to Send Personalized Emails with Attachments

  Рет қаралды 6,125

Laurence Svekis

Laurence Svekis

Жыл бұрын

How to Use Google Sheets and Apps Script to Send Personalized Emails with Attachments
How to Send Customized Emails with Attachments Using Google Apps Script and Google Sheets
This content is about using Google Sheets and Apps Script to select user information from a spreadsheet, constructing an email with a customized HTML file and PDF file attachment, and sending it to all users in the spreadsheet. The process involves creating a sender mail function and selecting the users' data from the spreadsheet. The content also includes instructions on how to loop through the values, get the user's name and ID, and construct an email using the mail app service.
#GoogleSheets #AppsScript #EmailAutomation #HTML #PDF #Attachment #Spreadsheet #DataSelection #MailAppService.
This article provides step-by-step instructions on how to create a script using Google Sheets that extracts data, constructs an email, and sends it out to users in the sheet. It also includes how to convert a Google Doc into a file and send it as an attachment, create an HTML file from data in the spreadsheet, and send attachments with the email. The tutorial covers using the Mail App service, looping through data, selecting sheet objects, and logging data in the console.
Send Email to Users from Sheet Make HTML and PDF files as attachments
#email #sheets #script #automate #googlesheets
This script sends an email to each user listed in the "Users" sheet of a Google Spreadsheet. The email contains the user's name, user ID, and an HTML body with some additional content.
Here is a step-by-step breakdown of the code:
The variable "id" contains the ID of the Google Drive file that will be used as an attachment in the email. This file is assumed to be a PDF document, and its ID is hardcoded into the script.
The "ss" variable contains the currently active Google Spreadsheet, and the "sheet" variable references the "Users" sheet within that spreadsheet.
The "rows" variable contains an array of all the rows in the "Users" sheet, except for the header row (which is skipped using the "slice" method).
A "forEach" loop is used to iterate over each row in the "rows" array.
Inside the loop, the script extracts the user's name, email, and user ID from the current row using array indexing.
The "subject" variable is set to a string that includes the user's name.
The "body" variable is set to an HTML string that includes the user's name and user ID.
The "html" variable is set to another HTML string that includes some additional content, as well as the "body" variable from step 7.
A new Blob object is created from the "html" string using the "Utilities.newBlob" method. This Blob will be used as an attachment in the email.
The "file" variable is set to a Drive file object that represents the PDF file with the hardcoded ID.
The "MailApp.sendEmail" method is called with several arguments:
The "to" field is set to the user's email address.
The "subject" field is set to the subject string from step 6.
The "htmlBody" field is set to the body string from step 7.
The "attachments" field is set to an array that includes the PDF file object from step 10 and the Blob object from step 9.
The script logs the user's name to the console for debugging purposes.
Overall, this script is useful for sending personalized emails to a group of users using data from a Google Spreadsheet. It demonstrates how to create an HTML email body and attach a file to the email using Google Apps Script.
Course content web development and web design courses with coding examples and source code for the lesson content. Source Code is available within my Github account. Lessons posted are designed to help students learn more about a specific topic related to modern web development and applying code.
Laurence Svekis is a professional top selling course author having instructed over 1 Million students both online and in person. Laurence Svekis is a Google Developer Expert specializing in Google Workspace automation using Google Apps Script Code.
Check out my Website for more details at basescripts.com/
Subscribe - www.youtube.com/@LaurenceSvek...
Tags and Keywords
#AppsScript #googlesheets #workspace #accounting #finance #automation modern web design online course #onlinecourses #modernwebdesign #tips #appsscript #coding #codingtutorial #script #scriptinghelp #google #Viral #subscribe #helping #GoogleAppsScript #Gmail #Attachments #Spreadsheet #Automation #GmailAttachments #GoogleAppsScript #EmailProductivity #Automation #SpreadsheetLogs #AttachmentDetails #TechTips #ProductivityHacks #GoogleDrive #GmailSearch #GoogleAppsScript #Spreadsheet #Email #Automation #Iteration #subscribe

Пікірлер: 11
@zoelee4561
@zoelee4561 Жыл бұрын
very helpful!
@LaurenceSvekisCourses
@LaurenceSvekisCourses Жыл бұрын
Thank you for watching
@koonerhospitalitygroup9688
@koonerhospitalitygroup9688 6 ай бұрын
Brilliant, thank you. 1 small question, is there any way to format the attachments as landscape orientation?
@jjc6530
@jjc6530 7 күн бұрын
How do you include bcc and cc?
@nikhileshpillai1107
@nikhileshpillai1107 Жыл бұрын
Also, can I send these from some other email platforms other than g mail?
@LaurenceSvekisCourses
@LaurenceSvekisCourses Жыл бұрын
No its apps script only connects to Workspace services
@Andy-yd1vq
@Andy-yd1vq 10 ай бұрын
Bcc and CC?
@nikhileshpillai1107
@nikhileshpillai1107 Жыл бұрын
Can I send Excel file as attachment?
@LaurenceSvekisCourses
@LaurenceSvekisCourses Жыл бұрын
do you mean a CSV or sheet?
@nikhileshpillai1107
@nikhileshpillai1107 Жыл бұрын
@@LaurenceSvekisCourses Excel file
@BatterFly2002
@BatterFly2002 Жыл бұрын
Hello, I have the following script, how can I add some dynamic value into the subject? Thanks function sendArticleCountEmails() { var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.setActiveSheet(ss.getSheetByName("Send-Emails")); var sheet = SpreadsheetApp.getActiveSheet(); var dataRange = sheet.getRange("A2:C2"); var data = dataRange.getValues(); for (i in data) { var rowData = data[i]; var emailAddress = rowData[1]; var recipient = rowData[0]; var message = rowData[2]; var message = 'Gentile ' + recipient + ', ' + message; var subject = 'Aggiornamento quotazione di Marzo - Batter Fly'; MailApp.sendEmail(emailAddress, subject, message); } }
Google Forms to PDF & Email while storing data in Google Sheets
27:02
Learn Google Sheets & Excel Spreadsheets
Рет қаралды 163 М.
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 35 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 16 МЛН
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН
UNO!
00:18
БРУНО
Рет қаралды 1,3 МЛН
Automate emails with Google Sheets
17:17
Matt Brigidi
Рет қаралды 19 М.
How to Send Automated Email using google apps script
6:10
Amarindaz
Рет қаралды 44 М.
How To Send Email Attachments with Google Apps Script
10:42
Data Meaning
Рет қаралды 15 М.
Google Sheets: Send Email When Condition Met
6:49
Spencer Farris
Рет қаралды 55 М.
Google Apps Script Send Emails from List
17:23
The Excel Cave
Рет қаралды 4,2 М.
Unlock the Secrets of PDF Generation with Google Apps Script
10:56
Google Developer Communities North America
Рет қаралды 18 М.
Gmail Mail Merge: Send Personalized Emails in Minutes
7:27
Teacher's Tech
Рет қаралды 10 М.
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 35 МЛН