2017-05-30 06:06:14 +00:00
|
|
|
var nodemailer = require('nodemailer');
|
2017-05-31 11:46:18 +00:00
|
|
|
var settings = require('./settings.js');
|
2017-05-31 12:55:41 +00:00
|
|
|
var path = require('path');
|
2017-05-30 06:06:14 +00:00
|
|
|
|
2017-05-31 16:19:55 +00:00
|
|
|
/**
|
|
|
|
* Módulo para el envío de emails
|
|
|
|
*/
|
2017-05-30 06:06:14 +00:00
|
|
|
module.exports = {
|
2017-05-30 06:06:14 +00:00
|
|
|
transporter: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Si todavía no está inicializada la configuración,
|
|
|
|
* carga el fichero de configuración.
|
|
|
|
*/
|
|
|
|
init: function() {
|
2017-05-31 11:46:18 +00:00
|
|
|
this.transporter = nodemailer.createTransport(settings.smtp());
|
2017-05-30 06:06:14 +00:00
|
|
|
|
|
|
|
this.transporter.verify(function(error, success) {
|
|
|
|
if (error) {
|
2017-06-01 06:51:29 +00:00
|
|
|
console.log(error);
|
2017-05-30 06:06:14 +00:00
|
|
|
} else {
|
2017-06-01 06:51:29 +00:00
|
|
|
console.log('Conexión SMTP establecida');
|
2017-05-30 06:06:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-05-31 16:19:55 +00:00
|
|
|
/**
|
|
|
|
* Envia un email con los datos recibidos desde un vector.
|
|
|
|
* @param {Object} data - Datos para el envío del email
|
|
|
|
*/
|
2017-05-30 06:06:14 +00:00
|
|
|
send: function(data) {
|
2017-05-31 12:55:41 +00:00
|
|
|
var filePath = 'Template/images/';
|
2017-05-30 06:06:14 +00:00
|
|
|
let mailOptions = {
|
2017-05-31 11:46:18 +00:00
|
|
|
from: '"' + settings.app().senderName + '" <' + settings.app().senderMail + '>',
|
2017-05-30 06:06:14 +00:00
|
|
|
to: data.recipient,
|
|
|
|
subject: data.subject,
|
2017-05-31 11:46:18 +00:00
|
|
|
html: data.body,
|
|
|
|
attachments: [
|
2017-05-31 12:55:41 +00:00
|
|
|
{filename: 'header.png', path: path.join(__dirname, filePath, 'header.png'), cid: 'header'},
|
|
|
|
{filename: 'arrow.png', path: path.join(__dirname, filePath, 'arrow.png'), cid: 'arrow'},
|
|
|
|
{filename: 'chat.png', path: path.join(__dirname, filePath, 'chat.png'), cid: 'chat'},
|
|
|
|
{filename: 'facebook.png', path: path.join(__dirname, filePath, 'facebook.png'), cid: 'facebook'},
|
|
|
|
{filename: 'twitter.png', path: path.join(__dirname, filePath, 'twitter.png'), cid: 'twitter'},
|
|
|
|
{filename: 'youtube.png', path: path.join(__dirname, filePath, 'youtube.png'), cid: 'youtube'},
|
|
|
|
{filename: 'pinterest.png', path: path.join(__dirname, filePath, 'pinterest.png'), cid: 'pinterest'},
|
|
|
|
{filename: 'instagram.png', path: path.join(__dirname, filePath, 'instagram.png'), cid: 'instagram'},
|
|
|
|
{filename: 'linkedin.png', path: path.join(__dirname, filePath, 'linkedin.png'), cid: 'linkedin'}
|
2017-05-31 11:46:18 +00:00
|
|
|
]
|
2017-05-30 06:06:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.transporter.sendMail(mailOptions, (error, info) => {
|
|
|
|
if (error) {
|
2017-06-01 06:51:29 +00:00
|
|
|
console.log(error);
|
2017-05-31 12:55:41 +00:00
|
|
|
} else if (settings.app().debug) {
|
2017-06-01 06:51:29 +00:00
|
|
|
console.log('Se ha enviado el email ' + info.messageId + ' [' + info.response + ']');
|
2017-05-30 06:06:14 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2017-05-31 16:19:55 +00:00
|
|
|
}
|
|
|
|
};
|