Email form with nodemailer - how to get the routes working?
See original GitHub issueI try to make a contact form in the front, that will send an email thru the nodemailer in the back - maybe someone has done thhis before and has a solution? Actually, my routes donβt work as expected, maybe I am doing something wrong?
var local_app = function () {}
// * ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ * //
// * init
// *
// * gets called upon starting enduro.js production server
// * @param {express app} app - express app
// * @return {nothing}
// * ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ * //
local_app.prototype.init = function (app) {
// express app available here
// don't forget these routes will be available on production server server (defaults to localhost:5000)//
// app.get('/random', function (req, res) {
// enduro.api.temper.render('random', { random_number: Math.random() })
// .then((output) => {
// res.send(output)
// })
// })
var nodemailer = require('nodemailer');
app.post('/sayHello', handleSayHello); // handle the route at yourdomain.com/sayHello
function handleSayHello(req, res) {
// Not the movie transporter!
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'example@gmail.com', // Your email id
pass: 'password' // Your password
}
});
var text = 'Hello world from \n\n' + req.body.name;
var mailOptions = {
from: 'example@gmail.com>', // sender address
to: 'xyz@gmail.com', // list of receivers
subject: 'Email Example', // Subject line
text: text //, // plaintext body
// html: '<b>Hello world β</b>' // You can choose to send an HTML body instead
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
res.json({yo: 'error'});
}else{
console.log('Message sent: ' + info.response);
res.json({yo: info.response});
};
});
}
}
module.exports = new local_app()
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Creating A Contact Form With JavaScript / Nodemailer
Hi Guys,Today we are going to be creating an email contact form using Nodemailer. I will be showing you how to set this...
Read more >Coding a Contact Form with Next.js and Nodemailer - Medium
Last thing to do is to get it all working, right? Going back to the contact.js code, there are two final things we...
Read more >How to Build a Contact Form with JavaScript and NodeMailer
Now all there's left to do is to set up the POST route to receive the submitted form data, parse it and send...
Read more >Contact form with nodemailer in nodejs - Strapengine
In this tutorial, we will be looking at how we can create a contact form with a nodemailer using Gmail's SMTP server in...
Read more >Sending Mail with Nodemailer in Node Application - Topcoder
Step 1. Setting up project: Β· Step 2. Configuring server.js and nodemailer Β· Step 3. Creating ejs form for mail. Β· Step 4....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Iβll just post my solution any way:
Here is the actual contact form:
Let me know if you have any questions
@sergejr to read the body you need to add app.use(bodyParser.json()); but this caused the Admin section to stop saving in save_cms so i had to use req.on(βdataβ,β¦ ,
below is my solution with basic Recaptcha integration.