This is my code:
userDetails = [{email:'email',id:'id'}]
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey('key');
for (const i in usersDetails) {
const user = usersDetails[i];
const msg = {
from: `ZdajTo<noreply@zdajto.com>`,
to: user.email,
subject: `Dostepne sa nowe zadania z kategorii ${work.category}!`,
html: `<p>Hej! Sprawdz aplikacje ZdajTo! Dostepne sa nowe zadania z kategorii ${work.category}! Aby zrezygnowac z otrzymywania emaili kliknij w <a href="https://Link/${user.id}" target="_blank">ten link</a></p>`,
};
calls.push(sgMail.send(msg).then(() => console.log(`Email sent to ${msg.to}`)).catch(e => console.log(e)));
}
return Promise.all(calls).then(() => console.log('Emails sent')).catch(err => console.log(8, err));
userDetails is an array of emails with ids.
I I used almost the same code earlier with nodemailer, and it worked well. Here's the nodemailer version:
for (const i in usersDetails) {
const user = usersDetails[i];
calls.push(mailTransport.sendMail({
from: `ZdajTo <noreply@zdajto.com>`,
to: user.email,
subject: `Dostepne sa nowe zadania z kategorii ${work.category}!`,
html: `<p>Hej! Sprawdz aplikacje ZdajTo! Dostepne sa nowe zadania z kategorii ${work.category}! Aby zrezygnowac z otrzymywania emaili kliknij w <a href="https://Link/${user.id}" target="_blank">ten link</a></p>`,
}).catch(err => console.log(7, err, user.email)));
}
The weird thing is, it says Emails sent
and Email sent to...
every time. No error is thrown, but at the same time SendGrid says there were no requests. Any idea what I'm missing?