import {getConfig, NodeConnectionMail} from "../helper/config"; import nodemailer from "nodemailer"; const config = getConfig(); /** * Get the instance of the transporter * @returns A transporter instance for sending out emails */ function getTransporter() : nodemailer.Transporter { // Generate the transporter const transporter = nodemailer.createTransport({ host: config?.smtp.host, port: config?.smtp.port, secure: config?.smtp.ssl, auth: { user: config?.smtp.username, pass: config?.smtp.password, } }); // Return the transporter return transporter; } /** * Send out an email with the config details. */ export async function sendMail(mailContent: string, toAddress: string, nodeConfig: NodeConnectionMail, ccAddresses?: Array) { // Get the transporter const transporter = getTransporter(); // Generate the mail options const mailOptions : nodemailer.SendMailOptions = { from: config?.smtp.email_from, to: nodeConfig.email_to, cc: nodeConfig.email_cc, html: mailContent, } await new Promise((_r, _e) => { transporter.sendMail(mailOptions, (err, info) => { }) }) transporter.close(); }