Skip to content

Instantly share code, notes, and snippets.

@ValentinGenev
Last active January 7, 2022 10:44
Show Gist options
  • Save ValentinGenev/df393af8d41ca101acd1e0a26ce8810c to your computer and use it in GitHub Desktop.
Save ValentinGenev/df393af8d41ca101acd1e0a26ce8810c to your computer and use it in GitHub Desktop.
Sends emails with data from Google sheet
3
email1@test.com email1@test.com email3@test.com
Hello, guys! This is an automated email. Kind regards, Valio
const SPREADSHEET = getSheet('send-emals')
function sendEmails() {
try{
const emailsCount = getCell(1)
const emails = getRowCells(2, emailsCount)
const emailTitle = getFileName()
const emailBody = getCell(3)
for (const email of emails) {
MailApp.sendEmail(email[0], emailTitle, emailBody)
}
}
catch(error){
Logger.log(error)
}
}
function getSheet(name) {
return SpreadsheetApp
.getActiveSpreadsheet()
.getSheetByName(name)
}
function getFileName() {
return SPREADSHEET.getParent().getName()
}
function getRowCells(row, cellsCount = 1, offset = 1) {
return SPREADSHEET
.getRange(row, offset, 1, cellsCount)
.getValues()
}
function getCell(row, column = 1) {
return SPREADSHEET
.getRange(row, column)
.getValue()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment