有没有一种方法可以使用 nodemailer 向不同的人发送不同的电子邮件?

Is there a way one can send different emails to different people using nodemailer?

我想给用户发一封邮件说

hey u have successfully registered please refer the code below 234234

以及给所有者的一封电子邮件说

user 234234 has registered 
            let transporter = nodemailer.createTransport({
                service: 'gmail',
                port: 587,
                secure: false,
                requireTLS: true,
                auth: {
                    user: MYEMAIL,
                    pass: MYPASSWORD,
                }
            })

            const randomGenerator = Math.floor(100000 + Math.random() * 900000)
        
            let mailOptions = {
                to: [
                            { name: "Receiver Name 1", address: "receiver1@example.com" },
                            { name: "Receiver Name 2", address: "receiver2@example.com" },
                    ], 
                subject: 'You have successfully registered, Please refer the code given below',
                text: `Your code is ${randomGenerator}`
            }
        
            transporter.sendMail(mailOptions, (err, info) => {
                if(err) console.log(err)
                else{
                    console.log('email sent' + info.response)
                }
            })

到目前为止,我已经尝试制作一个主题和文本数组,以便电子邮件按顺序发送它们,但相反,它向用户和所有者发送了两次相同的电子邮件

只需多次调用 .sendMail() 并在每次调用时为其提供不同的收件人和不同的电子邮件内容。对 .sendMail() 的一次调用具有一组收件人和一份电子邮件内容。因此,要发送不同的内容,请单独调用 .sendMail() 并改变输入。