import nodemailer from "nodemailer"; import { env } from "../src/config/env"; // Verifies the SMTP connection configured via env, and optionally sends a test mail. // Run with production env: set -a; . ./.env; set +a; pnpm tsx scripts/check-smtp.ts [recipient] async function main() { const recipient = process.argv[2]; const transport = nodemailer.createTransport({ host: env.SMTP_HOST, port: env.SMTP_PORT, secure: env.SMTP_PORT === 465, auth: { user: env.SMTP_USER, pass: env.SMTP_PASSWORD }, }); console.log( `Verifying SMTP ${env.SMTP_HOST}:${env.SMTP_PORT} (secure=${env.SMTP_PORT === 465}) as ${env.SMTP_USER}, from=${env.SMTP_FROM} …`, ); await transport.verify(); console.log("OK: SMTP connection verified."); if (recipient) { const info = await transport.sendMail({ from: env.SMTP_FROM, to: recipient, subject: "Redaktionsportal — SMTP-Test", text: "Test-E-Mail vom Redaktionsportal. Wenn diese ankommt, ist SMTP korrekt verbunden.", }); console.log(`OK: test mail sent to ${recipient} (messageId=${info.messageId}).`); } } main() .then(() => process.exit(0)) .catch((error) => { console.error("FAILED: SMTP check failed:", error?.message ?? error); process.exit(1); });