Add SMTP auth support and fix defaults (host.docker.internal, port 587)

This commit is contained in:
jochen
2026-03-29 00:45:48 +01:00
parent 0071549704
commit d8caf3ccac
2 changed files with 18 additions and 10 deletions
+12 -6
View File
@@ -6,9 +6,11 @@ const {
AMQP_EXCHANGE,
AMQP_QUEUE = "email-forwarder",
SMTP_HOST,
SMTP_PORT = "25",
SMTP_PORT = "587",
SMTP_USER,
SMTP_PASSWORD,
NOTIFY_TO,
NOTIFY_FROM = "hal@novox.be",
NOTIFY_FROM,
} = process.env;
async function main() {
@@ -20,15 +22,19 @@ async function main() {
await ch.bindQueue(AMQP_QUEUE, AMQP_EXCHANGE, "");
console.log(`Bound queue '${AMQP_QUEUE}' to exchange '${AMQP_EXCHANGE}'`);
const transport = nodemailer.createTransport({
const transportOpts = {
host: SMTP_HOST,
port: parseInt(SMTP_PORT),
secure: false,
tls: { rejectUnauthorized: false },
});
};
if (SMTP_USER && SMTP_PASSWORD) {
transportOpts.auth = { user: SMTP_USER, pass: SMTP_PASSWORD };
}
const transport = nodemailer.createTransport(transportOpts);
console.log(`SMTP: ${SMTP_HOST}:${SMTP_PORT}`);
console.log(`Forwarding to: ${NOTIFY_TO}`);
console.log(`SMTP: ${SMTP_USER || "(no auth)"}@${SMTP_HOST}:${SMTP_PORT}`);
console.log(`From: ${NOTIFY_FROM} → To: ${NOTIFY_TO}`);
console.log("Waiting for messages...\n");
ch.consume(AMQP_QUEUE, async (msg) => {