Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var router = express.Router();
- var nodemailer = require('nodemailer');
- /* GET home page. */
- router.get('/', function(req, res, next) {
- res.render('index', { title: 'Express' });
- });
- router.get('/index', function(req, res, next) {
- res.render('index', { title: 'Express' });
- });
- router.get('/about-us', function(req, res, next) {
- res.render('about-us', { title: 'Express' });
- });
- router.get('/contact-us', function(req, res, next) {
- res.render('contact-us', { title: 'Express' });
- });
- router.get('/services', function(req, res, next) {
- res.render('services', { title: 'Express' });
- });
- router.get('/support', function(req, res, next) {
- res.render('support', { title: 'Express' });
- });
- router.post('/enquiry', (req, res) => {
- const output = `
- <p>You have a New Enquiry</p>
- <h3>Enquiry Details</h3>
- <ul>
- <li>Name: ${req.body.name}</li>
- <li>Email: ${req.body.email}</li>
- <li>website: ${req.body.website}</li>
- </ul>
- <h3>Message</h3>
- <p>${req.body.message}</p>
- `;
- // create reusable transporter object using the default SMTP transport
- let transporter = nodemailer.createTransport({
- host: 'smtp.gmail.com',
- port: 465,
- secure: true, // true for 465, false for other ports
- auth: {
- user: 'akashvikas413@gmail.com', // generated ethereal user
- pass: 'anita@123' // generated ethereal password
- },
- // tls:{
- // rejectUnauthorized:false
- // }
- });
- // setup email data with unicode symbols
- let mailOptions = {
- from: 'akashvikas413@gmail.com', // sender address
- to: 'vinodmishra756@gmail.com', // list of receivers
- subject: 'New Enquiry', // Subject line
- text: 'From Brandzia Website', // 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.send(`<body style="background-color:gray;"><div style="position:absolute; width : 100%; height:5rem; text-align:center; font-size:2rem;top:50%;transform:translateY(-50%);">We Saved Your Enquiry. We will get in touch with you soon </div></body>`);
- });
- });
- module.exports = router;
Add Comment
Please, Sign In to add comment