Created
October 4, 2019 07:22
-
-
Save georgebyte/b8057567e49f369caee5afe4a9c07c37 to your computer and use it in GitHub Desktop.
Send daily email with a random quote from a Google Sheets document
This file contains 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
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