Why is my node mailer code not executing?

Viewed 50

I'm trying to send an email from my local hosted website built with react. When the user click the purchase button on a form it correctly executes some code but totally skips over the node mailer code without throwing any errors. I've gotten node mailer to succesfully send an email when its in its own .js file and is called directly from a command terminal. I just started learning React and node last week so I imagine this issue comes from a misunderstanding of how I'm supposed to implement node mailer. Any help is appreciated, thanks.

axios.post('http://localhost:5000/payment', user)

            .then(function (response) {
                // handle success
                setSuccess(true);
                console.log("before before");
                setPopup("Your ticket has been purchased. You may pick up your ticket at the will-call desk.");
                console.log("before");
                console.log("mailtime");


                let transporter = nodemailer.createTransport({
                  service: 'gmail',
                  auth: {
                    user: 'xxxxx@gmail.com',
                    pass: 'xxxx'
                  },
                });

                var mailOptions = {
                  from: 'tonycalzonecinemas@gmail.com',
                  to: 'myemail@gmail.com',
                  subject: 'Your ticket confirmation',
                  body: 'hello'
                };

                transporter.sendMail(mailOptions, function(error, info){
                    console.log('sending');
                    if (error) {
                      console.log(error);
                    } else {
                      console.log('Email sent: ' + info.response);
                    }
                  });

                console.log("confirmed");
            })

            .catch(function (error) {
                // handle error
                setSuccess(false);
                setPopup("Information is invalid. Please try again")
            })

            .finally(function () {
                console.log("always");
                // always executed
            });

        event.preventDefault() //stops browser clearing form
    }
0 Answers
Related