Guest User

Untitled

a guest
Oct 15th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import path from 'path';
  2. import config from '../../config/config';
  3.  
  4. const nodemailer = require('nodemailer');
  5. const EmailTemplate = require('email-templates');
  6.  
  7. const transporter = nodemailer.createTransport({
  8. service: 'gmail',
  9. port: 587,
  10. secure: false, // true for 465, false for other ports
  11. auth: {
  12. user: config.mail.user,
  13. pass: config.mail.pass
  14. }
  15. });
  16.  
  17. const emailEngine = new EmailTemplate({
  18. message: {
  19. from: 'duardbr@gmail.com'
  20. },
  21. transport: transporter,
  22. preview: true,
  23. send: true,
  24. juice: true,
  25. juiceResources: {
  26. preserveImportant: true,
  27. webResources: {
  28. relativeTo: path.resolve('public')
  29. }
  30. }
  31. });
  32.  
  33. function sendConfirmationRegisterLink(req, res) {
  34. const mailto = req.body.mailto;
  35.  
  36. const mensagem = {
  37. template: '../server/emails/templates/confirmation',
  38. message: {
  39. to: mailto
  40. },
  41. locals: {
  42. name: `${req.body.firstName} ${req.body.lastName}`
  43. }
  44. };
  45.  
  46. return sendOne(mensagem, res);
  47. }
  48.  
  49. function sendOne(msg, res) {
  50. console.log(`Sending mail to ${msg.message.to}`);
  51. emailEngine.send(msg, (err) => {
  52. if (err) { return res.status(500).send({ msg: err.message }); }
  53. return res.status(200).send(`A verification email has been sent to ${msg.message.to}.`);
  54. });
  55. }
  56.  
  57. export default { sendConfirmationRegisterLink };
Add Comment
Please, Sign In to add comment