I have a web project where sporting events are created and when creating an event I have to send an email, it is the first time I use nodemailer.
I'm doing shipping tests so for that I have a link that by clicking the driver of the url you must send the mail. but I get error. The codes are the following:
Link:
<a href="/admin/enviar">enviar correo</a>
JavaScript:
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: '*********'
}
});
router.get('/enviar', function (req, res, next) {
console.log("voy a enviar un correo");
var mailOptions = {
from: '"ColSport ?" <[email protected]>', // sender address
to: '[email protected], [email protected]', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ?', // plaintext body
html: '<b>Hello world ?</b>' // html body
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
res.redirect('back');
})
Result: