Sign in
Log inSign up

How to create a modal in node.js app?

Atul kumar's photo
Atul kumar
·Aug 12, 2018

I have written an function of nodemailer which as below :-

app.post('/sendemail', (req, res) => { const output = <p>You have a new contact request</p> <h3>Contact Details</h3> <ul> ; <li>Name: ${req.body.name}</li> <li>Email: ${req.body.email}</li> <li>Phone: ${req.body.phone}</li> </ul> <h3>Message</h3> <p>${req.body.message}</p>;

// create reusable transporter object using the default SMTP transport let transporter = nodemailer.createTransport({ service: 'gmail ',

auth: {
  user: '',
  pass: 'xxxxxxxxx'
},
tls: {
  rejectUnauthorized: false
}

});

// setup email data with unicode symbols let mailOptions = { from: '"Enquiry from datadock" atul.11192@gmail.com', // sender address to: '', // list of receivers subject: 'Datadock Enquiry ', // Subject line text: 'Hello world?', // plain text body html: output // html body };

// send mail with defined transport object transporter.sendMail(mailOptions, (error, info) => { if (error) { return console.log(error); } console.log('Message sent: %s', info.messageId); console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));

res.render('contacthanks.ejs', {
  message: 'Email has been sent'
});

/here i want to remove the redirection and show an modal for displaying success message with same page redirection**/ }); });

now upon success i want to display a modal (or popup) displaying success or error can anyone tell me how can i pass some information in the modal and show success or failure ?