59 lines
2.4 KiB
JavaScript
59 lines
2.4 KiB
JavaScript
var nodemailer = require('nodemailer');
|
|
var settings = require('./settings.js');
|
|
var logger = require('./logger.js');
|
|
|
|
// Módulo para el envío de emails
|
|
module.exports = {
|
|
|
|
transporter: null,
|
|
|
|
/**
|
|
* Si todavía no está inicializada la configuración,
|
|
* carga el fichero de configuración.
|
|
*/
|
|
init: function() {
|
|
this.transporter = nodemailer.createTransport(settings.smtp());
|
|
|
|
this.transporter.verify(function(error, success) {
|
|
if (error) {
|
|
logger.print(__LOG_ERROR, error);
|
|
} else {
|
|
logger.print(__LOG_INFO, 'Conexión SMTP establecida');
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Envia un email con los datos recibidos desde un vector.
|
|
* @param {Object} data - Datos para el envío del email
|
|
*/
|
|
send: function(data) {
|
|
let mailOptions = {
|
|
from: '"' + settings.app().senderName + '" <' + settings.app().senderMail + '>',
|
|
to: data.recipient,
|
|
subject: data.subject,
|
|
html: data.body,
|
|
attachments: [
|
|
{filename: 'header.png', path: './Application/Template/images/header.png', cid: 'header'},
|
|
{filename: 'arrow.png', path: './Application/Template/images/arrow.png', cid: 'arrow'},
|
|
{filename: 'chat.png', path: './Application/Template/images/chat.png', cid: 'chat'},
|
|
{filename: 'facebook.png', path: './Application/Template/images/facebook.png', cid: 'facebook'},
|
|
{filename: 'twitter.png', path: './Application/Template/images/twitter.png', cid: 'twitter'},
|
|
{filename: 'youtube.png', path: './Application/Template/images/youtube.png', cid: 'youtube'},
|
|
{filename: 'pinterest.png', path: './Application/Template/images/pinterest.png', cid: 'pinterest'},
|
|
{filename: 'instagram.png', path: './Application/Template/images/instagram.png', cid: 'instagram'},
|
|
{filename: 'linkedin.png', path: './Application/Template/images/linkedin.png', cid: 'linkedin'}
|
|
]
|
|
};
|
|
|
|
this.transporter.sendMail(mailOptions, (error, info) => {
|
|
if (error) {
|
|
logger.print(__LOG_ERROR, error);
|
|
} else if (settings.debug) {
|
|
logger.print(__LOG_INFO, 'Se ha enviado el email ' + info.messageId + ' [' + info.response + ']');
|
|
|
|
return true;
|
|
}
|
|
});
|
|
},
|
|
} |