Last active
January 7, 2022 10:44
-
-
Save ValentinGenev/df393af8d41ca101acd1e0a26ce8810c to your computer and use it in GitHub Desktop.
Sends emails with data from Google sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 | |||
---|---|---|---|
[email protected] | [email protected] | [email protected] | |
Hello, guys! This is an automated email. Kind regards, Valio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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