diff --git a/services/mailer/.gitignore b/services/mailer/.gitignore
index 36420af85..b66335f8f 100644
--- a/services/mailer/.gitignore
+++ b/services/mailer/.gitignore
@@ -1,2 +1,3 @@
node_modules
-config.json
\ No newline at end of file
+mailerMysql.json
+mailerSmtp.json
\ No newline at end of file
diff --git a/services/mailer/Application/Config/mailerApp.json b/services/mailer/Application/Config/mailerApp.json
new file mode 100644
index 000000000..b6b16e16a
--- /dev/null
+++ b/services/mailer/Application/Config/mailerApp.json
@@ -0,0 +1,9 @@
+{
+ "name": "MailServer",
+ "version": "1.0.0",
+ "port": 3003,
+ "debug": true,
+ "defaultLanguage": "es",
+ "senderMail": "nocontestar@verdnatura.es",
+ "senderName": "VerdNatura"
+}
\ No newline at end of file
diff --git a/services/mailer/Application/Language/es.paymentUpdate.json b/services/mailer/Application/Language/es.paymentUpdate.json
new file mode 100644
index 000000000..493e3bbfb
--- /dev/null
+++ b/services/mailer/Application/Language/es.paymentUpdate.json
@@ -0,0 +1,8 @@
+{
+ "subject": "Cambios en las condiciones de pago",
+ "title": "Cambio en las condiciones",
+ "dear": "Estimado cliente",
+ "bodyDescription": "Le enviamos este email para comunicarle que las condiciones de pago han cambiado. Le indicamos las nuevas condiciones a continuación.",
+ "fiscalAddress": "VERDNATURA LEVANTE SL, B97367486 Avda. Espioca, 100, 46460 Silla _ www.verdnatura.es _ clientes@verdnatura.es",
+ "privacy": "Este mensaje es privado y confidencial, y debe ser utilizado exclusivamente por la persona destinataria del mismo. Si usted ha recibido este mensaje por error, le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. Verdnatura Levante SL no renuncia a la confidencialidad ni a ningún privilegio por causa de transmisión errónea o mal funcionamiento. Igualmente no se hace responsable de los cambios, alteraciones, errores u omisiones que pudieran hacerse al mensaje una vez enviado."
+}
\ No newline at end of file
diff --git a/services/mailer/Application/Route/manuscript.js b/services/mailer/Application/Route/manuscript.js
index a229fd499..05ec7cb8b 100644
--- a/services/mailer/Application/Route/manuscript.js
+++ b/services/mailer/Application/Route/manuscript.js
@@ -7,18 +7,15 @@ var template = require('../template.js');
// Escrito de cambios en méto de pago del cliente
router.post('/paymentUpdate', function(request, response) {
database.pool.query('SELECT Cliente, `e-mail` AS email FROM Clientes WHERE Id_Cliente = ?', [request.body.user], function(error, rs) {
+
+ //Datos del escrito
var params = {
clientName: rs[0].Cliente
};
-
- template.getTemplate('paymentUpdate', params, function(body) {
- var data = {
- recipient: rs[0].email,
- subject: 'Cambios en las condiciones de pago',
- body: body
- };
-
- if (mail.send(data)) {
+
+ //Obtener plantilla y enviar
+ template.getTemplate('paymentUpdate', 'es', params, function(tplResult) {
+ if (mail.send({recipient: rs[0].email, subject: tplResult.subject, body: tplResult.body})) {
response.json({status: "OK"});
} else {
response.json({status: "ERROR"});
diff --git a/services/mailer/Application/Template/images/arrow.png b/services/mailer/Application/Template/images/arrow.png
new file mode 100644
index 000000000..66e5de833
Binary files /dev/null and b/services/mailer/Application/Template/images/arrow.png differ
diff --git a/services/mailer/Application/Template/images/chat.png b/services/mailer/Application/Template/images/chat.png
new file mode 100644
index 000000000..0bec1ab86
Binary files /dev/null and b/services/mailer/Application/Template/images/chat.png differ
diff --git a/services/mailer/Application/Template/images/download.png b/services/mailer/Application/Template/images/download.png
new file mode 100644
index 000000000..d18174177
Binary files /dev/null and b/services/mailer/Application/Template/images/download.png differ
diff --git a/services/mailer/Application/Template/images/facebook.png b/services/mailer/Application/Template/images/facebook.png
new file mode 100644
index 000000000..7ab54c538
Binary files /dev/null and b/services/mailer/Application/Template/images/facebook.png differ
diff --git a/services/mailer/Application/Template/images/header.png b/services/mailer/Application/Template/images/header.png
new file mode 100644
index 000000000..3c063ae44
Binary files /dev/null and b/services/mailer/Application/Template/images/header.png differ
diff --git a/services/mailer/Application/Template/images/instagram.png b/services/mailer/Application/Template/images/instagram.png
new file mode 100644
index 000000000..66550c4a5
Binary files /dev/null and b/services/mailer/Application/Template/images/instagram.png differ
diff --git a/services/mailer/Application/Template/images/linkedin.png b/services/mailer/Application/Template/images/linkedin.png
new file mode 100644
index 000000000..0d191e5ae
Binary files /dev/null and b/services/mailer/Application/Template/images/linkedin.png differ
diff --git a/services/mailer/Application/Template/images/pinterest.png b/services/mailer/Application/Template/images/pinterest.png
new file mode 100644
index 000000000..4d7b28ef8
Binary files /dev/null and b/services/mailer/Application/Template/images/pinterest.png differ
diff --git a/services/mailer/Application/Template/images/twitter.png b/services/mailer/Application/Template/images/twitter.png
new file mode 100644
index 000000000..c4a8ab0c1
Binary files /dev/null and b/services/mailer/Application/Template/images/twitter.png differ
diff --git a/services/mailer/Application/Template/images/youtube.png b/services/mailer/Application/Template/images/youtube.png
new file mode 100644
index 000000000..11871deb5
Binary files /dev/null and b/services/mailer/Application/Template/images/youtube.png differ
diff --git a/services/mailer/Application/Template/paymentUpdate.html b/services/mailer/Application/Template/paymentUpdate.html
index 203db8047..02b0abebf 100644
--- a/services/mailer/Application/Template/paymentUpdate.html
+++ b/services/mailer/Application/Template/paymentUpdate.html
@@ -1,35 +1,74 @@
-
-
-
![](https://verdnatura.es/image/logo.png)
-
- Verdnatura Levante SL, B97367486
- Avda. Espioca 100, 46460 Silla (Valencia)
-
-
-
-
-
CAMBIOS EN CONDICIONES DE PAGO
-
+
+
+
+
{{subject}}
+
+
+
+
+
+
+
![VerdNatura](cid:header)
+
+
+
+
{{title}}
+
+
-
- Estimado cliente {{clientName}}
-
+
+
+
{{dear}} {{clientName}},
+
{{bodyDescription}}
-
- Se han cambiado las condiciones de pago, estas son las nuevas:
-
-
-
-
-
Este mensaje es privado y confidencial, y debe ser utilizado exclusivamente por la persona destinataria del mismo.
- Si usted ha recibido este mensaje por error, le rogamos lo comunique al remitente y borre dicho mensaje y cualquier
- documento adjunto que pudiera contener. Verdnatura Levante SL no renuncia a la confidencialidad ni a ningún privilegio
- por causa de transmisión errónea o mal funcionamiento. Igualmente no se hace responsable de los cambios, alteraciones,
- errores u omisiones que pudieran hacerse al mensaje una vez enviado.
-
-
En cumplimiento de lo dispuesto en la Ley Orgánica 15/1999, de Protección de Datos de Carácter Personal, le comunicamos
- que los datos personales que facilite se incluirán en ficheros automatizados de VERDNATURA LEVANTE S.L., pudiendo en todo momento
- ejercitar los derechos de acceso, rectificación, cancelación y oposición, comunicándolo por escrito al domicilio social de la entidad.
- La finalidad del fichero es la gestión administrativa, contabilidad, y facturación.
-
-
\ No newline at end of file
+
??
+
??
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{{fiscalAddress}}
+
- AVISO - Este mensaje es privado y confidencial, y debe ser utilizado exclusivamente por la persona destinataria del mismo. Si usted ha recibido este mensaje por error, le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. Verdnatura Levante SL no renuncia a la confidencialidad ni a ningún privilegio por causa de transmisión errónea o mal funcionamiento. Igualmente no se hace responsable de los cambios, alteraciones, errores u omisiones que pudieran hacerse al mensaje una vez enviado.
+
En cumplimiento de lo dispuesto en la Ley Orgánica 15/1999, de Protección de Datos de Carácter Personal, le comunicamos que los datos personales que facilite se incluirán en ficheros automatizados de VERDNATURA LEVANTE S.L., pudiendo en todo momento ejercitar los derechos de acceso, rectificación, cancelación y oposición, comunicándolo por escrito al domicilio social de la entidad. La finalidad del fichero es la gestión administrativa, contabilidad, y facturación.
+
+
+
+
+
\ No newline at end of file
diff --git a/services/mailer/Application/database.js b/services/mailer/Application/database.js
index 979867a33..5682b3e5b 100644
--- a/services/mailer/Application/database.js
+++ b/services/mailer/Application/database.js
@@ -1,6 +1,6 @@
var mysql = require('mysql');
-var settings = require('./Settings.js');
-var logger = require('./Logger.js');
+var settings = require('./settings.js');
+var logger = require('./logger.js');
module.exports = {
@@ -13,7 +13,7 @@ module.exports = {
* Iniciar pool de conexión con la base de datos
*/
init: function() {
- this.pool = mysql.createPool(settings.mysql);
+ this.pool = mysql.createPool(settings.mysql());
this.pool.getConnection(function(error, connection) {
if (error) {
diff --git a/services/mailer/Application/language.js b/services/mailer/Application/language.js
index e69de29bb..0d04a3bee 100644
--- a/services/mailer/Application/language.js
+++ b/services/mailer/Application/language.js
@@ -0,0 +1,23 @@
+var fs = require('fs');
+var settings = require('./settings.js');
+var logger = require('./logger.js');
+
+module.exports = {
+
+ /**
+ * Devuelve las claves de idioma de una plantilla
+ * @param {String} templateName - Nombre de la plantilla
+ * @param {String} langCode - Código de idioma
+ * @return {Object} Devuelve el objeto con las claves de idioma
+ */
+ load: function(templateName, langCode) {
+ // Comprobamos que exista una traducción para esta plantilla
+ if (fs.existsSync('./Application/Language/' + langCode + '.' + templateName + '.json')) {
+ return require('./Language/' + langCode + '.' + templateName + '.json');
+ } else if(fs.existsSync('./Application/Language/' + settings.defaultLanguage + '.' + templateName + '.json')){
+ return require('./Language/' + settings.defaultLanguage + '.' + templateName + '.json');
+ } else {
+ logger.print(__LOG_ERROR, 'No se ha encontrado ninguna traducción para la plantilla ' + templateName + '.');
+ }
+ }
+}
\ No newline at end of file
diff --git a/services/mailer/Application/mail.js b/services/mailer/Application/mail.js
index 3390425fe..8b2ddd34c 100644
--- a/services/mailer/Application/mail.js
+++ b/services/mailer/Application/mail.js
@@ -1,6 +1,6 @@
var nodemailer = require('nodemailer');
-var settings = require('./Settings.js');
-var logger = require('./Logger.js');
+var settings = require('./settings.js');
+var logger = require('./logger.js');
// Módulo para el envío de emails
module.exports = {
@@ -12,7 +12,7 @@ module.exports = {
* carga el fichero de configuración.
*/
init: function() {
- this.transporter = nodemailer.createTransport(settings.smtp);
+ this.transporter = nodemailer.createTransport(settings.smtp());
this.transporter.verify(function(error, success) {
if (error) {
@@ -29,16 +29,27 @@ module.exports = {
*/
send: function(data) {
let mailOptions = {
- from: '"' + settings.senderName + '" <' + settings.senderMail + '>',
+ from: '"' + settings.app().senderName + '" <' + settings.app().senderMail + '>',
to: data.recipient,
subject: data.subject,
- html: data.body
+ 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) {
+ } else if (settings.debug) {
logger.print(__LOG_INFO, 'Se ha enviado el email ' + info.messageId + ' [' + info.response + ']');
return true;
diff --git a/services/mailer/Application/router.js b/services/mailer/Application/router.js
index c18f908a9..6bc5e60bf 100644
--- a/services/mailer/Application/router.js
+++ b/services/mailer/Application/router.js
@@ -4,7 +4,7 @@ var settings = require('./settings.js');
// Página por defecto
router.get('/', function(request, response) {
- response.send(settings.name + ' v' + settings.version);
+ response.send(Settings.name + ' v' + settings.version);
});
// Rutas de los escritos.
diff --git a/services/mailer/Application/settings.js b/services/mailer/Application/settings.js
index f2a22d5d3..27369c1c6 100644
--- a/services/mailer/Application/settings.js
+++ b/services/mailer/Application/settings.js
@@ -1,2 +1,24 @@
// Módulo de configuración
-module.exports = require('./config.json');
+module.exports = {
+
+ /**
+ * Configuración de la aplicación
+ */
+ app: function() {
+ return require('./Config/mailerApp.json');
+ },
+
+ /**
+ * Configuración de smtp
+ */
+ smtp: function() {
+ return require('./Config/mailerSmtp.json');
+ },
+
+ /**
+ * Configuración de mysql
+ */
+ mysql: function() {
+ return require('./Config/mailerMysql.json');
+ }
+}
diff --git a/services/mailer/Application/template.js b/services/mailer/Application/template.js
index 3424c0dd2..9593ed694 100644
--- a/services/mailer/Application/template.js
+++ b/services/mailer/Application/template.js
@@ -2,30 +2,33 @@ var fs = require('fs');
var mustache = require('mustache');
var database = require('./database.js');
var logger = require('./logger.js');
-
+var language = require('./language.js');
var Template = {
/**
* Obtiene la plantilla
- * @param {String} name - Nombre de la plantilla
+ * @param {String} templateName - Nombre de la plantilla
* @param {Object} params - Datos a reemplazar.
* @param {Object} callback - Callback
*/
- getTemplate: function(name, params, callback) {
- database.pool.query('SELECT name, attachmentPath FROM vn.mailTemplates WHERE name = ?', [name], function(error, rs)
+ getTemplate: function(templateName, langCode, params, callback) {
+ database.pool.query('SELECT name, attachmentPath FROM vn.mailTemplates WHERE name = ?', [templateName], function(error, rs)
{
+ // Comprobamos que exista la plantilla
if (rs.length == 0) {
- logger.print(__LOG_ERROR, 'La plantilla ' + name + ' no existe');
+ logger.print(__LOG_ERROR, 'La plantilla ' + templateName + ' no existe');
return;
}
+ var langParams = language.load(templateName, langCode);
+ params = Object.assign({}, langParams, params);
var path = './Application/Template/' + rs[0].name + '.html';
if (!fs.existsSync(path)) {
logger.print(__LOG_ERROR, 'No se ha podido cargar la plantilla ' + name + '.html');
} else {
- Template.render(path, params, function(body) {
- callback(body);
+ Template.render(path, params, function(tplBody) {
+ callback({subject: params.subject, body: tplBody});
});
}
});
@@ -34,6 +37,7 @@ var Template = {
/**
* Renderiza las plantillas
* @param {String} path - Ruta de la plantilla
+ * @param {String} language - Idioma
* @param {Object} params - Listado de parámetros a remplazar
* @param {Object} callback - Callback
*/
@@ -42,7 +46,7 @@ var Template = {
mustache.parse(body);
callback(mustache.render(body, params));
});
- }
+ },
};
module.exports = Template;
diff --git a/services/mailer/package.json b/services/mailer/package.json
index 87aced84e..c78bfc567 100644
--- a/services/mailer/package.json
+++ b/services/mailer/package.json
@@ -1,13 +1,13 @@
{
- "name": "MailServer",
- "version": "0.0.1",
- "description": "Servidor de envío de correos",
- "main": "server.js",
- "dependencies": {
- "body-parser": "^1.17.2",
- "express": "^4.15.3",
- "mustache": "^2.3.0",
- "mysql": "^2.13.0",
- "nodemailer": "^4.0.1"
- }
-}
+ "name": "MailServer",
+ "version": "0.0.1",
+ "description": "Servidor de envío de correos",
+ "main": "server.js",
+ "dependencies": {
+ "mysql": "^2.13.0",
+ "express": "^4.15.3",
+ "body-parser": "^1.17.2",
+ "nodemailer": "^4.0.1",
+ "mustache": "^2.3.0"
+ }
+}
\ No newline at end of file
diff --git a/services/mailer/server.js b/services/mailer/server.js
index 448c9b922..c85695670 100644
--- a/services/mailer/server.js
+++ b/services/mailer/server.js
@@ -2,7 +2,7 @@
* Módulos necesarios
*/
var express = require('express');
-var app = module.exports = express();
+var app = express();
var bodyParser = require('body-parser');
var settings = require('./Application/settings.js');
@@ -18,20 +18,21 @@ app.use(bodyParser.urlencoded({extended: true}));
// Cargar rutas
app.use('/', require('./Application/router.js'));
+// Iniciar escucha del servidor
+app.listen(settings.app().port, function() {
+ // Imprimir cabecera
+ terminal.printHeader();
-app.start = function() {
- return app.listen(settings.port, function() {
- terminal.printHeader();
- mail.init();
- database.init();
- logger.print(__LOG_INFO, 'Servidor de correo iniciado en el puerto ' + settings.port);
- if (settings.debug) {
- logger.print(__LOG_WARNING, 'El modo debug está activado');
- }
- });
-};
+ // Escucha SMTP
+ mail.init();
-if (require.main === module) {
- app.start();
-}
+ // Iniciar base de datos
+ database.init();
+
+ logger.print(__LOG_INFO, 'Servidor de correo iniciado en el puerto ' + settings.app().port);
+
+ if (settings.debug) {
+ logger.print(__LOG_WARNING, 'El modo debug está activado');
+ }
+});