Advertisement
Guest User

server.js

a guest
Mar 28th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by tiffanyraill on 2017-03-28.
  3.  */
  4. var express=require('express');
  5. var nodemailer = require("nodemailer");
  6. var router = express.Router();
  7. /*
  8.  Here we are configuring our SMTP Server details.
  9.  STMP is mail server which is responsible for sending and recieving email.
  10.  */
  11. var smtpTransport = nodemailer.createTransport({
  12.     service: "gmail",
  13.     host: "smtp.gmail.com",
  14.     auth: {
  15.         user: ' ',
  16.         pass: ' '
  17.     }
  18. });
  19. /*------------------SMTP Over-----------------------------*/
  20.  
  21. /*------------------Routing Started ------------------------*/
  22.  
  23. router.get('/',function(req,res){
  24.     res.sendfile('contactMe.ejs');
  25. });
  26. router.post('/send',function(req,res){
  27.     console.log(req.body)
  28.     var mailOptions={
  29.         subject: req.body.name,
  30.         to: '<miss tiffanys email address>',
  31.         text: req.body.comments
  32.     };
  33.     console.log(mailOptions);
  34.     smtpTransport.sendMail(mailOptions, function(error, response){
  35.         if(error){
  36.             console.log(error);
  37.             res.end("error");
  38.         }else{
  39.             console.log("Message sent: " + response.message);
  40.             res.end("sent");
  41.         }
  42.     });
  43. });
  44.  
  45. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement