Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const transport = nodemailer.createTransport({
- host: process.env.MAIL_HOST,
- port: process.env.MAIL_PORT,
- auth: {
- user: process.env.MAIL_USER,
- pass: process.env.MAIL_PASS
- }
- });
- const generateHTML = (filename, options = {}) => {
- const html = pug.renderFile(`${__dirname}/../views/email/${filename}.pug`,
- options);
- const inlined = juice(html);
- return inlined;
- }
- exports.send = async (options) => {
- const html = generateHTML(options.filename, options);
- const text = htmlToText.fromString(html);
- const mailOptions = {
- from: `Site <noreply@domain.com>`,
- to: options.user.email,
- subject: options.subject,
- html,
- text
- };
- const sendMail = P.promisify(transport.sendMail, transport);
- return sendMail(mailOptions);
- }
- const transport = nodemailer.createTransport({
- host: process.env.MAIL_HOST,
- port: process.env.MAIL_PORT,
- auth: {
- user: process.env.MAIL_USER,
- pass: process.env.MAIL_PASS
- }
- });
- const generateHTML = (filename, options = {}) => {
- const html = pug.renderFile(`${__dirname}/../views/email/${filename}.pug`,
- options);
- const inlined = juice(html);
- return inlined;
- }
- exports.send = async (options) => {
- const html = generateHTML(options.filename, options);
- const text = htmlToText.fromString(html);
- const mailOptions = {
- from: `Site <noreply@domain.com>`,
- to: options.user.email,
- subject: options.subject,
- html,
- text
- };
- transport.sendMail(mailOptions, function (error, info) {
- if (error) {
- console.log(error);
- } else {
- console.log('Email sent: ' + info.response);
- }
- });
- }
Add Comment
Please, Sign In to add comment