import * as nodemailer from "nodemailer"; import { fetchMeta } from "backend-rs"; import Logger from "@/services/logger.js"; import { config } from "@/config.js"; import { inspect } from "node:util"; export const logger = new Logger("email"); export async function sendEmail( to: string, subject: string, html: string, text: string, ) { const meta = await fetchMeta(false); const iconUrl = `${config.url}/static-assets/mi-white.png`; const emailSettingUrl = `${config.url}/settings/email`; const enableAuth = meta.smtpUser != null && meta.smtpUser !== ""; const transporter = nodemailer.createTransport({ host: meta.smtpHost, port: meta.smtpPort, secure: meta.smtpSecure, ignoreTLS: !enableAuth, proxy: config.proxySmtp, auth: enableAuth ? { user: meta.smtpUser, pass: meta.smtpPass, } : undefined, } as any); try { const info = await transporter.sendMail({ from: meta.email!, to: to, subject: subject, text: text, html: ` ${subject}

${meta.name}

${subject}

${html}
`, }); logger.info(`Message sent: ${info.messageId}`); } catch (err) { logger.error(inspect(err)); throw err; } }