diff --git a/app.js b/app.js index ef688e1..d94002c 100644 --- a/app.js +++ b/app.js @@ -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) => { diff --git a/module.yml b/module.yml index 333fae2..e5a478a 100644 --- a/module.yml +++ b/module.yml @@ -1,6 +1,6 @@ manifest: 2 name: amqp-email-forwarder -version: "1.0.0" +version: "1.0.1" description: "Consumes CloudEvents from AMQP and forwards as email notifications" service: @@ -35,13 +35,15 @@ env: AMQP_QUEUE: default: "email-forwarder" SMTP_HOST: - default: "localhost" + default: "host.docker.internal" SMTP_PORT: - default: "25" + default: "587" + SMTP_USER: + SMTP_PASSWORD: NOTIFY_TO: default: "jochen.schoubben@mediahuis.be" NOTIFY_FROM: - default: "hal@novox.be" + default: "jschoubben@novox.be" package: - docker-compose.yml