Reputation:
transporter.sendMail(mailOptions,(error,info)=>{
if(error) console.log(error)
console.log('Message Sent: '+info.messageId)
console.log('Preview URL: '+nodemailer.getTestMessageUrl(info))
res.redirect('contacts',{msg:'Email has been sent'})
});
I am using nodemailer
to send mail, I have configured it correctly, but what could be the possible reason that I am getting undefined
when I am logging the value of info
into the console?
Upvotes: 0
Views: 145
Reputation: 5072
Most likely info
is not being set because there is an error. You would have to confirm by looking at their source.
You can, however, account for this by changing your code slightly, like so:
transporter.sendMail(mailOptions,(error, info)=>{
if (error) {
return console.log(error);
}
console.log('Message Sent: '+info.messageId)
console.log('Preview URL: '+nodemailer.getTestMessageUrl(info))
res.redirect('contacts',{msg:'Email has been sent'})
});
This way if error
is set, it will log the error and return before falling through the rest of your code. This is similar to the example on their page.
Upvotes: 1