/** * Archivo que contiene brinda la funcionadad enviar correo electronico para EMA Libre. * * Contiene un conjunto de funciones de envio de correo electronico para EMA. * * LICENSE: This file is part of EMA Libre. * EMA Libre is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * EMA Libre is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with EMA Libre. If not, see . * * @copyright Copyright (c) 2019 GUGLER (http://www.gugler.com.ar) * @license https://www.gnu.org/licenses/gpl-3.0.html GPL License * @version 3.0 * @link http://www.gugler.com.ar * @since File available since Release 3.0 */ /********************************************** LIBRERIA PARA ENVIAR EMAIL ***********************************************/ // Variables Generales const nodeMailer = require('nodemailer'); // Se incluye la libreria para enviar Correo. /*FUNCION AUXILIARES */ function RegistrarLog (reg, depurar) { if (typeof depurar !== 'undefined') { depurar = false; } // se convierte la fecha a la UTC parametrizada var d = new Date(); var utc = d.getTime() + (d.getTimezoneOffset() * 60000); var fechaHora = new Date(utc + (3600000 * (C_EMA.ConfGeneral.UTC))); var horas = fechaHora.getHours(); var minutos = fechaHora.getMinutes(); var segundos = fechaHora.getSeconds(); var mes = fechaHora.getMonth() + 1; var dia = fechaHora.getDate(); if (dia <= 9) { dia = '0' + dia; } if (mes <= 9) { mes = '0' + mes; } if (horas < 10) { horas = '0' + horas; } if (minutos < 10) { minutos = '0' + minutos; } if (segundos < 10) { segundos = '0' + segundos; } var fecha = dia + '/' + mes + '/' + fechaHora.getFullYear() + ' ' + horas + ':' + minutos + ':' + segundos; var registrologs = fecha + ' - ' + util.format(reg) + '\n'; if (depurar) { // SE DEPURA EL ARCHIVO DE REGISTROS DE LOGS fs.writeFile('./logs/debug.log', '', { encoding: 'utf8', autoClose: true }, function (err) { if (err) { RegistrarLog('0|ERROR|Depurando archivo registro de logs :' + err); } }); } else { // GUARDA LOS REGISTROS DE LOGS fs.appendFile('./logs/debug.log', registrologs, { encoding: 'utf8', autoClose: true }, function (err) { if (err) { RegistrarLog('0|ERROR|Guardando registro de logs en archivo :' + err); } }); } registrologs=null;fecha=null;dia=null;mes=null;segundos=null;minutos=null;horas=null;fechaHora=null;utc=null;d=null; } module.exports = { EnviarEmail: function (ConfGeneral, Asunto, Cuerpo) { // Definimos el transportador var transportador; if (ConfGeneral.ConfEmail.Servicio !== 'Manual') { transportador = nodeMailer.createTransport({ service: ConfGeneral.ConfEmail.Servicio, auth: { user: ConfGeneral.ConfEmail.Usuario, pass: ConfGeneral.ConfEmail.Password } }); } else { transportador = nodeMailer.createTransport({ host: ConfGeneral.ConfEmail.Server, port: ConfGeneral.ConfEmail.Puerto, auth: { user: ConfGeneral.ConfEmail.Usuario, pass: ConfGeneral.ConfEmail.Password } }); } // Definimos el cuerpo del correo var mailOptions = { from: 'EMA LIBRE - GUGLER', to: ConfGeneral.ConfEmail.ReceptorEmail, subject: Asunto, html: Cuerpo }; // Enviamos el email transportador.sendMail(mailOptions, function (error, info) { if (error) { RegistrarLog('1|CORREO| Error en el envio de correo. Verifique los datos de configuración. '); } else { RegistrarLog('1|CORREO| Correo electronico enviado correctamente.'); } }); transportador = null;mailOptions=null; } };