Last active
August 23, 2022 13:20
-
-
Save albertopasqualetto/3ed9ac2eab83df51f2f932bada73832f to your computer and use it in GitHub Desktop.
Schedule this gmail
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
//FILL THIS LIST AND ADD 1 (OR MORE) TRIGGERS TO SEND | |
// This is the list of mails to send; add a new line for each email to send daily. | |
// 'recipient' needs to be specified; 'subject' and 'body' are not needed. | |
const listToSend = new Set([ | |
{recipient:"[email protected]", subject:"subject0", body:"body0"}, | |
{recipient:"[email protected]", subject:"subject1", body:"body1"}, | |
{recipient:"[email protected]", subject:"subject2", body:"body2"} | |
]); | |
/****************************************************************************************************/ | |
/** | |
* This is the main function. | |
* Sends all the emails and updates the triggers. | |
*/ | |
function sendScheduledEmails() { | |
const now = new Date(); | |
listToSend.forEach(function(value){ | |
try{ | |
GmailApp.sendEmail(value.recipient, value.subject, value.body); | |
console.info("[" + now.toDateString() + "] Email sent to: " + value.recipient); | |
} catch(err){ | |
console.error("[" + now.toDateString() + "] Error in sending email to: " + value.recipient); | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a Google Apps Script which schedules the emails in the list above to be sent at every execution (activated by triggers).
Copy this code in a new Google Apps Script project, add Gmail as service, fill the list at the top of the code with each email and setup one or more triggers to run sendScheduledEmails function.