I am trying to get nodemail and nodemail-mailgun to send an email. (Eventually form submission results).
I have tried searching on SO as well as just general google and I cannot seem to find someone with the same issue.
The Setup:
const nodemailer = require('nodemailer');
const mg = require('nodemailer-mailgun-transport'),
bodyParser = require('body-parser');
const auth = {
auth: {
api_key: 'REMOVED FOR SECURITY',
domain: 'REMOVED FOR SECURITY'
}
}
const nodemailerMailgun = nodemailer.createTransport(mg(auth));
The Route:
router.post('/contact', function(req, res, next) {
console.log('Send Mail...');
nodemailerMailgun.sendMail({
from: "no-reply@airsafetynw.com",
to: 'john.s@airsafetynw.com', // An array if you have multiple recipients.
cc:'adam.f.wilkinson@gmail.com',
subject: 'Air Safety NW contact form',
//You can use "html:" to send HTML email content. It's magic!
html: '<b>From:</b></br>',
//You can use "text:" to send plain-text content. It's oldschool!
text: ""
}, (err, info) => {
if (err) {
console.log(`Error: ${err}`);
}
else {
res.send('Successful!')
}
});
});
The Error:
asnw > Error: TypeError: Cannot read property 'id' of undefined
POST /contact - - ms - -
I have removed ALL js variables in my template in hopes that maybe one of them was incorrect however if I res.send or console.log the req.body.variable above the .sendmail they work just fine. If someone knows where I can look for the 'id' so I can figure out what is not defined I might be able to move forward.