Files
anouma/lib/email/transport.ts
T
maro ad353190f3
CI / test (push) Canceled after 0s
Release / promote-and-deploy (push) Canceled after 0s
CI / build-image (push) Canceled after 0s
Fix SMTP proxy certificates and speed up CI
2026-09-18 11:59:33 +02:00

35 lines
1.2 KiB
TypeScript

import nodemailer from "nodemailer";
let cached: nodemailer.Transporter | null = null;
/** SMTP transporter for the existing ANOUMA mail system - no external newsletter service. */
export function getMailTransport(): nodemailer.Transporter {
if (cached) return cached;
const { SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD } = process.env;
if (!SMTP_HOST || !SMTP_PORT || !SMTP_USER || !SMTP_PASSWORD) {
throw new Error("SMTP_HOST, SMTP_PORT, SMTP_USER and SMTP_PASSWORD must be set to send email.");
}
cached = nodemailer.createTransport({
host: SMTP_HOST,
port: Number(SMTP_PORT),
secure: Number(SMTP_PORT) === 465,
tls: {
// Keep certificate verification enabled by default. A private SMTP
// proxy may expose a self-signed certificate; that deployment can
// explicitly opt out without weakening unrelated HTTPS requests.
rejectUnauthorized: process.env.SMTP_TLS_REJECT_UNAUTHORIZED !== "false",
},
connectionTimeout: 10000,
greetingTimeout: 10000,
socketTimeout: 20000,
auth: { user: SMTP_USER, pass: SMTP_PASSWORD },
});
return cached;
}
export function getMailFrom(): string {
return process.env.SMTP_FROM || "ANOUMA <support@anouma.org>";
}