0
nodemailerを使用してデータベース(mongodb)に保存されている複数の受信者にメールを送信する方法はありますか? 現在、1人の受信者に送信しています。しかし、私はmongodbにメールIDが格納されている複数の人にメールを送る方法を理解できません。nodemailerを使用して複数の受信者にメールを送信
誰かが回答を知っている場合は、回答してください。 ありがとうございます。
nodemailerを使用してデータベース(mongodb)に保存されている複数の受信者にメールを送信する方法はありますか? 現在、1人の受信者に送信しています。しかし、私はmongodbにメールIDが格納されている複数の人にメールを送る方法を理解できません。nodemailerを使用して複数の受信者にメールを送信
誰かが回答を知っている場合は、回答してください。 ありがとうございます。
電子メールを送信するすべてのemail_addressの配列を取得するにはmongodb distingを使用し、その配列をnodemailerに渡します。
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'yourpass'
}
});
let email_arr = db.users.distinct("email", { /* Any condition you want to put*/ })
let mailOptions = {
from: "[email protected]", // sender address
subject: "Hello ✔", // Subject line
text: "Hello This is an auto generated Email for testing from node please ignore it", // plaintext body
to: email_arr
}
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
これは魅力のように機能します。アイデアをありがとう。 – Nobody
すべての受信者メールをカンマで区切ります。または、bccまたはccを使用できます。 –