简体   繁体   English

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

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

I want to send an email to the user saying我想向用户发送 email 说

hey u have successfully registered please refer the code below 234234

and an email to the owner saying和一个 email 给业主说

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)
                }
            })

so far i've tried making an array of subject and text so that the email sends them orderwise, but instead, it sent the same email to the user and owner twice到目前为止,我已经尝试制作主题和文本数组,以便 email 按顺序发送它们,但是相反,它向用户和所有者发送了相同的 email 两次

Just call .sendMail() more than once and feed it different addressees and different email content each time you call it.只需多次调用.sendMail()并在每次调用时提供不同的收件人和不同的 email 内容。 One call to .sendMail() has one set of addressees and one piece of email content..sendMail()的一次调用有一组收件人和一份 email 内容。 So, to send different content, use separate calls to .sendMail() and vary the inputs.因此,要发送不同的内容,请使用对.sendMail()的单独调用并改变输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM