简体   繁体   English

Nodemailer:未定义收件人,如何解决?

[英]Nodemailer: No recipients Defined, how to fix?

When trying to send data from a form on a react.js component I am getting this error when I push the submit button to send the data to an e-mail address:当我尝试从 react.js 组件上的表单发送数据时,当我按下提交按钮将数据发送到电子邮件地址时出现此错误:

Error: No recipients defined错误:未定义收件人

Can anyone tell me how I can fix this issue to get the data sending to an e-mail address I want?谁能告诉我如何解决这个问题以将数据发送到我想要的电子邮件地址?

Here is my mail.js file code:这是我的 mail.js 文件代码:

const { Email } = require("./email_template");


const getEmailData = (template) => {
    let data = null;

    switch (template) {
        case "hello":
            data = {
                from: "Contact Form",
                to: "matthew.devonport.test@gmail.com",
                subject: `Message from the contact form!`,
                html: Email()
            }
            break;

        default:
            data;
    }
    return data;
}


const sendEmail = (to, name, type) => {

    const smtpTransport = mailer.createTransport({
        service: "Gmail",
        auth: {
            user: "testemail@gmail.com",
            pass: "testpass"
        }
    })

    const mail = getEmailData(to, name, type)

    smtpTransport.sendMail(mail, function(error, response) {
        if(error) {
            console.log(error)
        } else {
            alert( "Thank you! We will be in touch shortly!")
        }
        smtpTransport.close();
    })


}

module.exports = { sendEmail }```

Check your input to your function:检查您对函数的输入:

getEmailData(template)

When you invoke the method in sendEmail you don't match the input parameters当您调用 sendEmail 中的方法时,您与输入参数不匹配

const mail = getEmailData(to, name, type)

Which returns null and gives the error implying on missing data.它返回 null 并给出暗示丢失数据的错误。

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

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