Matthew-Devonport
Matthew-Devonport

Reputation: 75

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: "[email protected]",
                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: "[email protected]",
            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 }```

Upvotes: 2

Views: 3058

Answers (1)

Heenke
Heenke

Reputation: 21

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.

Upvotes: 1

Related Questions