I have been trying for months to get my Task Scheduler to send out a daily email. I can’t for the life of mine get it to work. I’ve looked all over this forum and tried it many different ways. Still can’t get this email to send. I am using SendGrid.
Here is the jobs.config code:
{
"jobs": [{
"functionLocation": "/xxxxxxxxxxxxx/xxxxxxxxxxx.jsw",
"functionName": "xxxxxxxxxxx",
"description": "xxxxxxxxxxxxxxxxx",
"executionConfig": {
"time": "xx:xx"
}
},
{
"functionLocation": "email.jsw",
"functionName": "DailyReminder",
"description": "Daily Reminder",
"executionConfig": {
"time": "19:25"
}
}
]
}
And here is the code in Backend/email.jsw:
export async function DailyReminder() {
sgMail.setApiKey('SG.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
const msg = {
from: {
email: 'me@example.com',
name: 'My Name Goes here'
},
templateId: 'd-xxxxxxxxxxxxxxxxxxxx'
};
wixData.query("EmailList")
.limit(999)
.eq("subscribed", true)
.eq("contactType", "ADMIN")
.find()
.then((results) => {
let items = results.items
let recipients = ""
if (results.items.length > 0) {
recipients = items.map(function (val) {
return val.email;
})
recipients = "testingemail@gmail.com, testingemail2@gmail.com"
msg.to = recipients
return sgMail.sendMultiple(msg)
.then(() => {
console.log("Email sent to " + recipients)
return "Email sent to " + recipients
})
.catch(error => {
console.log(error)
return error;
});
} else {
console.log("no members based on filter")
}
})
.catch((err) => {
let errorMsg = err;
});
}