- nodemailer-express-handlebars
- nodemailer
- handlebars
- @types/nodemailer
- winston
- express-winston
- @types/express-winston
| import nodemailer from 'nodemailer'; | |
| import path from 'path'; | |
| import { Incident } from '../models/incident.model'; | |
| import * as utils from '../utils/utils'; | |
| // tslint:disable-next-line: no-var-requires | |
| const hbs = require('nodemailer-express-handlebars'); | |
| // Configuración de handlebars | |
| const hbsConfig = { | |
| viewEngine: { | |
| extName: '.hbs', | |
| partialsDir: path.join(__dirname, '../views/'), | |
| layoutsDir: path.join(__dirname, '../views/'), | |
| defaultLayout: '' | |
| }, | |
| viewPath: path.join(__dirname, '../views/'), | |
| extName: '.hbs' | |
| }; | |
| // Configuración transportador NodeMailer | |
| const transporter = nodemailer.createTransport({ | |
| service: 'gmail', | |
| auth: { user: process.env.USER, pass: process.env.PASSWORD } | |
| }); | |
| /** | |
| * Envia un correo al administrador y copia a los involucrados en el evento | |
| * @param incident : Incident | |
| */ | |
| async function notifyNewIncident(incident: Incident) { | |
| transporter.use('compile', hbs(hbsConfig)); | |
| const ccValues = []; | |
| if (incident.assignedTo !== incident.createdBy) { | |
| ccValues.push(incident.createdBy); | |
| ccValues.push(incident.assignedTo); | |
| } else { | |
| ccValues.push(incident.createdBy); | |
| } | |
| const email = { | |
| from: 'Soporte Neox', | |
| to: process.env.USER, | |
| cc: ccValues, | |
| subject: '👀 Hola ' + incident.company, | |
| template: 'newIncident', | |
| context: { incident } | |
| }; | |
| await transporter.sendMail(email).catch(error => { | |
| utils.logger.error(error); | |
| }); | |
| } |
It is a logger