0

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?

Alex Ironside
  • 4,658
  • 11
  • 59
  • 119

1 Answers1

1

My assumption is you're getting an accepted response (202) which triggers the "message sent" part. however, it doesn't guarantee that your message will be sent i just queue it to process. i would contact Sendgrid support as in this case: Sendgrid returns 202 but doesn't send email

sanchedale
  • 166
  • 1
  • 7