mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
Previously, logs were not very friendly and it was hard to track a request because of the lack of request ID. Now every log message comes with a header containing: method, path request ID, session ID, IP of the user, date. Moreover, the configurations displayed in the logs have their secrets hidden from this commit.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { IMailSender } from "./IMailSender";
|
|
import Nodemailer = require("nodemailer");
|
|
import NodemailerDirectTransport = require("nodemailer-direct-transport");
|
|
import NodemailerSmtpTransport = require("nodemailer-smtp-transport");
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
export class MailSender implements IMailSender {
|
|
private transporter: Nodemailer.Transporter;
|
|
|
|
constructor(options: NodemailerDirectTransport.DirectOptions |
|
|
NodemailerSmtpTransport.SmtpOptions, nodemailer: typeof Nodemailer) {
|
|
this.transporter = nodemailer.createTransport(options);
|
|
}
|
|
|
|
verify(): BluebirdPromise<void> {
|
|
const that = this;
|
|
return new BluebirdPromise(function (resolve, reject) {
|
|
that.transporter.verify(function (error: Error, success: any) {
|
|
if (error) {
|
|
reject(new Error("Unable to connect to SMTP server. \
|
|
Please check the service is running and your credentials are correct."));
|
|
return;
|
|
}
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
|
|
send(mailOptions: Nodemailer.SendMailOptions): BluebirdPromise<void> {
|
|
const that = this;
|
|
return new BluebirdPromise(function (resolve, reject) {
|
|
that.transporter.sendMail(mailOptions, (error: Error,
|
|
data: Nodemailer.SentMessageInfo) => {
|
|
if (error) {
|
|
reject(new Error("Error while sending email: " + error.message));
|
|
return;
|
|
}
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
} |