https://stackoverflow.com/questions/64412815/sending-multiple-emails-at-once-with-nodemailer
static async resendUndeliveredMails() {
try {
const mails = await findAll();
const mailerPromises = mails.map((mail) => transporter.sendMail(mail.dataValues));
const responses = await Promise.all(mailerPromises);
console.log(responses, "All Mails Have Been Sent Successfully");
} catch (e) {
console.log(e);
}
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "user",
pass: "pass", // naturally, replace both with your real credentials or an application-specific password
},
});
const mailOptions = {
from: "user@gmail.com",
to: "test@gmail.com",
subject: "testing due",
text: "Dudes, we really need your money.",
};
const mailOptions2 = {
from: "user@gmail.com",
to: "test1@gmail.com",
subject: "LOL due",
text: "Dudes, we really need your money.",
};
Promise.all([
transporter.sendMail(mailOptions),
transporter.sendMail(mailOptions2),
])
.then((res) => console.log(res))
.catch((err) => console.log(err));
Không có nhận xét nào:
Đăng nhận xét