Guest User

Untitled

a guest
Jan 14th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. const nodemailer = require('nodemailer');
  2. const pug = require('pug');
  3. const juice = require('juice');
  4. const htmlToText = require('html-to-text');
  5. const promisify = require('es6-promisify');
  6.  
  7. const transport = nodemailer.createTransport({
  8. host: process.env.MAIL_HOST,
  9. port: process.env.MAIL_PORT,
  10. auth: {
  11. user: process.env.MAIL_USER,
  12. pass: process.env.MAIL_PASS
  13. }
  14. });
  15.  
  16. const generateHTML = (filename, options={}) => {
  17. const html = pug.renderFile(`${__dirname}/../views/email/${filename}.pug`);
  18. const inlinedCSS = juice(html);
  19. return inlinedCSS;
  20. };
  21.  
  22. exports.send = async (options) => {
  23. // console.log(options);
  24. const html = generateHTML(options.filename, options);
  25. const text = htmlToText.fromString(html);
  26. const optionMail = {
  27. from: 'Gromov <test@gmail.com>',
  28. to: options.user.email,
  29. filename: 'password-reset',
  30. subject: options.subject,
  31. html,
  32. text
  33. };
  34. const sendMail = promisify(transport.sendMail, transport);
  35. return sendMail(optionMail);
  36. };
Add Comment
Please, Sign In to add comment