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: 'atul.11192@gmail.com',
pass: 'xxxxxxxxx'
},
tls: {
rejectUnauthorized: false
}
});
// setup email data with unicode symbols let mailOptions = { from: '"Enquiry from datadock" atul.11192@gmail.com', // sender address to: 'atul.11192@gmail.com', // 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 ?
What's your front-end? node.js is back-end and as such has no mechanism for realtime making a modal client-side unless you're sending that output client-side somewhere. If that's a dynamic modal that means client-side AJAX, if it's on-load you'd just be outputting it and then setting up some form of control to it.
Either way it's not something node.js by itself can even do. Modals are client/render side so what's your client/render?
Nicolas Cloutier
Senior e-commerce and blockchain developer
have you looked at express-flash or express-flash-notifications? here is a url: npmjs.com/package/express-flash-notification
you could also use socket.io to monitor events but I think with express flash is best for that kind of work