Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. var express = require('express');
  2. var router = express.Router();
  3. var nodemailer = require('nodemailer');
  4.  
  5. /* GET home page. */
  6. router.get('/', function(req, res, next) {
  7. res.render('index', { title: 'Index' });
  8. });
  9.  
  10. /* GET contact. */
  11. router.get('/contact', function(req, res, next) {
  12. res.render('contact', { title: 'Contact' });
  13. });
  14.  
  15. /* POST sendmessage. */
  16. router.post('/contact', function(req, res, next) {
  17.  
  18. var transporter = nodemailer.createTransport({
  19. service: 'gmail',
  20. auth: {
  21. user: 'cipformacion2019@gmail.com',
  22. pass: 'Abcd.1234'
  23. }
  24. });
  25.  
  26. const mailOptions = {
  27. from: 'cipformacion2019@gmail.com', // sender address
  28. //to: 'jgglez79@gmail.com', // list of receivers
  29. to: req.body.email,
  30. subject: 'prueba', // Subject line
  31. html: '<p>Esto es una prueba</p>'// plain text body
  32. };
  33.  
  34. transporter.sendMail(mailOptions, function (err, info) {
  35. if(err) {
  36. res.render('contact', { title: 'Contact', message: 'No se ha podido enviar el mensaje' });
  37. console.log(err);
  38. }
  39. else {
  40. res.render('contact', { title: 'Contact', message: 'Mensaje enviado' });
  41. console.log(info);
  42. }
  43. });
  44.  
  45.  
  46. console.log(mailOptions);
  47. console.log(req.body);
  48.  
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement