Skip to content

Commit

Permalink
fix(mail): corrige error envío mail
Browse files Browse the repository at this point in the history
  • Loading branch information
MCele committed May 10, 2023
1 parent f497c29 commit bb88498
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 19 deletions.
136 changes: 120 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"node-pushnotifications": "^1.0.18",
"node-sass": "^7.0.0",
"node-schedule": "^1.2.4",
"nodemailer": "^6.9.1",
"passport": "^0.3.2",
"passport-jwt": "^4.0.0",
"pdfkit": "^0.9.0",
Expand Down Expand Up @@ -185,4 +186,4 @@
"ts-jest": "^24.1.0",
"tslint-eslint-rules": "^4.1.1"
}
}
}
29 changes: 27 additions & 2 deletions utils/roboSender/sendEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import moment = require('moment');
import { services } from '../../services';
const handlebars = require('handlebars');
const path = require('path');

const nodemailer = require('nodemailer');
handlebars.registerHelper('datetime', dateTime => {
return moment(dateTime).format('D MMM YYYY [a las] H:mm [hs]');
});
Expand All @@ -18,9 +18,34 @@ export interface MailOptions {
attachments?: any;
}

async function EmailClient(options) {
const data = {
host: 'exchange2016.hospitalneuquen.org.ar',
port: 25,
tls: {
rejectUnauthorized: false
}
};
const transporter = nodemailer.createTransport(data);
const mailOptions = {
from: options.from,
to: options.to,
subject: options.subject,
text: options.text,
html: options.html,
attachments: options.attachments
};
return transporter.sendMail(mailOptions);
}

export async function sendMail(options: MailOptions, servicioAlternativo: string = null) {
const servicio = servicioAlternativo || 'email-send-default';
return services.get(servicio).exec(options);
if (servicio === 'email-send-hpn') {
await EmailClient(options);
} else {
return services.get(servicio).exec(options);
}

}

export function renderHTML(templateName: string, extras: any): Promise<string> {
Expand Down

0 comments on commit bb88498

Please sign in to comment.