I am trying to send an email based on the entries inside a database using nodemailer
. I have tried practically anything I can think of (manually creating an array of Promises
and using that in a call of Promise.all()
, doing that using a map
, etc.), but I always keep getting the same error: UnhandledPromiseRejectionWarning: Error: Message failed: 450 SQLITE_ERROR: cannot start a transaction within a transaction
. The nodemailer
-documentation clearly states that -- when not passing a callback-fn, the transporter.sendMail()
-function is wrapped as a promise. However, when I am manually defining an array of those promises like so...
const transporter = nodemailer.createTransport(serverData);
const mailData = ...;
const arr = [transporter.sendMail(mailData), transporter.sendMail(mailData)];
... the same error already fires even though I have not even 'ran' through that array using Promise.all()
; is it a misconception that the functions in the array will only run when I manually specify?
Anyhow, this is my complete code for the database; I am using sequelize
to retrieve the data from the database. I have verified that there are no problems on the retrieving-data-from-the-db-side of this task.
class Mail extends Model {
...
static resendUndeliveredMails(){
this.findAll()
.then((mails) => {
return Promise.all(mails.map(async mail => {
transporter.sendMail(mail.dataValues);
}));
})
.catch((e) => {
console.log(e);
});
}
}
Any help would be greatly appreciated! Thank you in advance :).