Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import path from 'path';
- import config from '../../config/config';
- const nodemailer = require('nodemailer');
- const EmailTemplate = require('email-templates');
- const transporter = nodemailer.createTransport({
- service: 'gmail',
- port: 587,
- secure: false, // true for 465, false for other ports
- auth: {
- user: config.mail.user,
- pass: config.mail.pass
- }
- });
- const emailEngine = new EmailTemplate({
- message: {
- from: 'duardbr@gmail.com'
- },
- transport: transporter,
- preview: true,
- send: true,
- juice: true,
- juiceResources: {
- preserveImportant: true,
- webResources: {
- relativeTo: path.resolve('public')
- }
- }
- });
- function sendConfirmationRegisterLink(req, res) {
- const mailto = req.body.mailto;
- const mensagem = {
- template: '../server/emails/templates/confirmation',
- message: {
- to: mailto
- },
- locals: {
- name: `${req.body.firstName} ${req.body.lastName}`
- }
- };
- return sendOne(mensagem, res);
- }
- function sendOne(msg, res) {
- console.log(`Sending mail to ${msg.message.to}`);
- emailEngine.send(msg, (err) => {
- if (err) { return res.status(500).send({ msg: err.message }); }
- return res.status(200).send(`A verification email has been sent to ${msg.message.to}.`);
- });
- }
- export default { sendConfirmationRegisterLink };
Add Comment
Please, Sign In to add comment