I have a website with a contact form where clients can submit a question. The form is already working with Nodemailer and sending the submitted form to my email. Now I want to send an autoresponse to the client, whenever the client submits the form. So the client receives an email back with something like "Thank you for your message, I will be replying soon", but I don't know how to do this with Nodemailer.
This is my Nodemailer code:
router.get('includes/contact', function(req, res) {
res.render('contact',{title:'Contact'});
});
//route to send the form
router.post('/contact/send', function(req, res) {
var transporter = nodeMailer.createTransport({
service : 'Gmail',
auth : {
user: process.env.GMAIL_USER,
pass: process.env.GMAIL_PASS
}
});
var mailOptions = {
from: req.body.name + ' <' + req.body.email + '>',
to: '[email protected]',
subject:'Website verzoek',
text:'Er is een website verzoek binnengekomen van '+ req.body.name+' Email: '+req.body.email+'Soort website: '+req.body.website+'Message: '+req.body.message,
html:'<p>Websiteverzoek van: </p><ul><li>Naam: '+req.body.name+' </li><li>Email: '+req.body.email+' </li><li>Soort website: '+req.body.website+' </li><li>Message: '+req.body.message+' </li></ul>'
};
transporter.sendMail(mailOptions, function (err, info) {
if(err) {
console.log(err);
res.redirect('/#contact');
} else {
console.log('Message send');
res.redirect('/#contact');
}
});
});