Add SMTP auth support and fix defaults (host.docker.internal, port 587)
This commit is contained in:
@@ -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) => {
|
||||
|
||||
+6
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user