Skip to content

Instantly share code, notes, and snippets.

@georgebyte
Created October 4, 2019 07:22
Show Gist options
  • Save georgebyte/b8057567e49f369caee5afe4a9c07c37 to your computer and use it in GitHub Desktop.
Save georgebyte/b8057567e49f369caee5afe4a9c07c37 to your computer and use it in GitHub Desktop.
Send daily email with a random quote from a Google Sheets document
function sendDailyWisdom() {
var FIRST_ROW = 2;
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var rows = ss.getRange(FIRST_ROW, 1, ss.getLastRow(), 1).getValues();
var randomWisdomRow = Math.floor(Math.random() * (rows.length - FIRST_ROW + 1)) + FIRST_ROW;
var randomWisdom = ss.getRange(randomWisdomRow, 1).getValue();
var source = ss.getRange(randomWisdomRow, 2).getValue();
var htmlBody =
'<div style="width: 500px; font-family: Times New Roman; font-size: 18px;">' +
randomWisdom +
'</div>' +
'<div style="width: 500px; margin-top: 16px; font-family: Times New Roman; font-size: 14px; font-style: italic; text-align: right;">― ' +
source +
'</div>';
MailApp.sendEmail({
to: '<email>',
subject: "Daily wisdom",
htmlBody: htmlBody,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment