简体   繁体   中英

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:

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:

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

const mail = getEmailData(to, name, type)

Which returns null and gives the error implying on missing data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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