Added more explicit type for SMTP config and refactored transport initialization.
This commit is contained in:
parent
d2ca8ed55b
commit
13e4895b81
6 changed files with 84 additions and 43 deletions
29
server/mail/index.ts
Normal file
29
server/mail/index.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import {createTransport, Transporter} from "nodemailer";
|
||||
import {config} from "../config";
|
||||
import * as MailTemplateService from "../services/mailTemplateService";
|
||||
import Mail from "nodemailer/lib/mailer";
|
||||
import SMTPTransport from "nodemailer/lib/smtp-transport";
|
||||
|
||||
let transporterSingleton: Transporter | null = null;
|
||||
|
||||
function transporter() {
|
||||
if (!transporterSingleton) {
|
||||
const options = {
|
||||
...config.server.email.smtp,
|
||||
pool: true,
|
||||
};
|
||||
transporterSingleton = createTransport(new SMTPTransport(options));
|
||||
|
||||
MailTemplateService.configureTransporter(transporterSingleton);
|
||||
}
|
||||
|
||||
return transporterSingleton;
|
||||
}
|
||||
|
||||
export function init(): void {
|
||||
transporter();
|
||||
}
|
||||
|
||||
export async function send(options: Mail.Options): Promise<void> {
|
||||
await transporter().sendMail(options);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue