Skip to content

Instantly share code, notes, and snippets.

@ndthanh

ndthanh/sendMailOnSchedule.js Secret

Created Jul 15, 2021
Embed
What would you like to do?
// Author: Nguyễn Đức Thanh
// Web: https://blog.hocexcel.online
// Elearning: https://hocexcel.online
// Elearning for business: https://dtnguyen.business
// YouTube: https://youtube.com/hocexcelonline
function sendMailOnBirthday() {
const today = new Date()
const month = today.getMonth() + 1
const date = today.getDate()
const data = SpreadsheetApp.getActive().getSheetByName('data').getDataRange().getValues()
const list = data.filter(record => record[2] === month && record[3] === date)
if(list.length > 0) {
list.forEach(record => {
let mailTo = record[0]
let subject = "Mail được gửi tự động"
let body = "Body"
mySendMail(mailTo, subject, body)
SpreadsheetApp.getActive().getSheetByName('log').appendRow([ `Đã gửi mail tới ${mailTo} vào lúc ${new Date()}` ])
})
}
}
function mySendMail(mailTo, subject, body) {
MailApp.sendEmail(mailTo, subject, body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment