I ve tried different loop function to send mail from my cloud database. the code below sends the mail but I can't send mail that contain details specific to each recipiant
I want to loop through my database collection and send mails asynchronously.
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
////we would use receipt for the testing of the loop
//google account credentials used to send email
var transporter = nodemailer.createTransport({
host: "smtp.example.com",
port: 587,
secure: true,
auth: {
user: '***********@fastfood.com',
pass: '********'
}
});
exports.newsletters = functions.firestore
.document('Puns/{orderId}')
.onWrite((snap, context)=> {
var Emails = ['Cyrilogoh@gmail.com', 'mariajame34@gmail.com','therealogoh@gmail.com','faraway@gmail.com']
const mailOptions = {
from: `cyrilogoh@gmail.com`,
to: Emails,
subject: `test`,
html: `<h1>test</h1>
<p>
Array Works
</p>`
};
return transporter.sendMail(mailOptions, (error, data) => {
if (error) {
console.log(error)
return
}
console.log("Sent!")
});
});```