daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 209 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const transport = nodemailer.createTransport({
  2.   host: process.env.MAIL_HOST,
  3.   port: process.env.MAIL_PORT,
  4.   auth: {
  5.     user: process.env.MAIL_USER,
  6.     pass: process.env.MAIL_PASS
  7.   }
  8. });
  9.  
  10. const generateHTML = (filename, options = {}) => {
  11.   const html = pug.renderFile(`${__dirname}/../views/email/${filename}.pug`,
  12.     options);
  13.   const inlined = juice(html);
  14.   return inlined;
  15. }
  16.  
  17. exports.send = async (options) => {
  18.   const html = generateHTML(options.filename, options);
  19.   const text = htmlToText.fromString(html);
  20.   const mailOptions = {
  21.     from: `Site <noreply@domain.com>`,
  22.     to: options.user.email,
  23.     subject: options.subject,
  24.     html,
  25.     text
  26.   };
  27.   const sendMail = P.promisify(transport.sendMail, transport);
  28.   return sendMail(mailOptions);
  29. }
  30.    
  31. const transport = nodemailer.createTransport({
  32.       host: process.env.MAIL_HOST,
  33.       port: process.env.MAIL_PORT,
  34.       auth: {
  35.         user: process.env.MAIL_USER,
  36.         pass: process.env.MAIL_PASS
  37.       }
  38.     });
  39.  
  40.     const generateHTML = (filename, options = {}) => {
  41.       const html = pug.renderFile(`${__dirname}/../views/email/${filename}.pug`,
  42.         options);
  43.       const inlined = juice(html);
  44.       return inlined;
  45.     }
  46.  
  47.     exports.send = async (options) => {
  48.       const html = generateHTML(options.filename, options);
  49.       const text = htmlToText.fromString(html);
  50.       const mailOptions = {
  51.         from: `Site <noreply@domain.com>`,
  52.         to: options.user.email,
  53.         subject: options.subject,
  54.         html,
  55.         text
  56.       };
  57.       transport.sendMail(mailOptions, function (error, info) {
  58.         if (error) {
  59.             console.log(error);
  60.         } else {
  61.             console.log('Email sent: ' + info.response);
  62.         }
  63.         });
  64.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top