Nodemailer multiple recipients
To send the mail to multiple users you have to place them in a data type String, separated by commas, an example
const arrayUsersMail = ['emailOne@example.com', 'emailTwo@example.com', 'emailThree@example.com', 'emailFour@example.com' ]const stringUsersMail = arrayUsersMail.join(', ')nodemailerMailgun.sendMail({from: 'myemail@example.com',to: stringUsersMail,subject: 'Event Invitation',html: renderToString(<InvitationEmail from="myemail@example.com" to="WHAT HERE" eventId={eventId} />)
})
While @Potier97's answer is correct, I strongly recommend you instead send each recipient a separate e-mail (aka loop through your list of recipients and call sendMail
for each). This is because sending an e-mail to multiple recipients means each recipient get the exact same e-mail. The can also see all the other recipients and can Reply to all. I don't know about your specific use case but it's very unlikely that you actually want to do this
const emails = ['email1@gmail.com', 'email2@gmail.com'];for (const email of emails) { nodemailerMailgun.sendMail({ from: 'myemail@example.com', to: email, subject: 'Event Invitation', html: renderToString(<InvitationEmail from="myemail@example.com" to={email} eventId={eventId} />) })}