From 9f25f29b7f8d68d5b52e4bee4c7ac0f51560fd55 Mon Sep 17 00:00:00 2001 From: torbinus Date: Mon, 26 Oct 2026 10:21:24 +0100 Subject: [PATCH] Testbetrieb: alle Mails an eine Adresse umleiten MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ist MAIL_TEST_EMPFAENGER gesetzt, gehen sämtliche Mails dorthin statt an den eigentlichen Empfänger; der Betreff nennt den ursprünglichen. So kann das Testsystem echte Mails verschicken, ohne dass etwas bei Kunden ankommt. In der Produktion bleibt die Variable leer (steht im Livegang-Plan). Co-Authored-By: Claude Opus 5.5 (1M context) --- LIVEGANG.md | 1 + backend/apps/backend/medusa-config.ts | 1 + .../src/modules/email-notification/service.ts | 18 +++++++++++++++--- compose.prod.yml | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/LIVEGANG.md b/LIVEGANG.md index f8a925c..ae120f4 100644 --- a/LIVEGANG.md +++ b/LIVEGANG.md @@ -64,6 +64,7 @@ STORE_CORS=https://place4bees.com ADMIN_CORS=https://place4bees.com AUTH_CORS=https://place4bees.com GA_ID= +MAIL_TEST_EMPFAENGER= ``` **DHL umstellen** — beide Schalter, in dieser Reihenfolge: diff --git a/backend/apps/backend/medusa-config.ts b/backend/apps/backend/medusa-config.ts index ff1f753..e3028e7 100644 --- a/backend/apps/backend/medusa-config.ts +++ b/backend/apps/backend/medusa-config.ts @@ -92,6 +92,7 @@ module.exports = defineConfig({ user: process.env.SMTP_USER, pass: process.env.SMTP_PASSWORD, from: process.env.MAIL_FROM, + testRecipient: process.env.MAIL_TEST_EMPFAENGER || undefined, }, } : { diff --git a/backend/apps/backend/src/modules/email-notification/service.ts b/backend/apps/backend/src/modules/email-notification/service.ts index 5731801..f61857c 100644 --- a/backend/apps/backend/src/modules/email-notification/service.ts +++ b/backend/apps/backend/src/modules/email-notification/service.ts @@ -9,6 +9,11 @@ type Options = { user?: string; pass?: string; from: string; + /** + * Zum Testen: alle Mails gehen an diese Adresse statt an den Empfänger. + * So kommt beim Testen nichts bei echten Kunden an. + */ + testRecipient?: string; }; /** @@ -64,11 +69,14 @@ class EmailNotificationService extends AbstractNotificationProviderService { // können, ohne die Adresse aus dem Text zu kopieren. const antwortAn = (notification.data as any)?.reply_to; + const umgeleitet = this.options_.testRecipient; + const an = umgeleitet || notification.to; + const info = await this.transporter_.sendMail({ from: notification.from || this.options_.from, ...(typeof antwortAn === "string" && antwortAn ? { replyTo: antwortAn } : {}), - to: notification.to, - subject: content.subject, + to: an, + subject: umgeleitet ? `[TEST an ${notification.to}] ${content.subject}` : content.subject, text: content.text, html: content.html, attachments: (notification.attachments ?? []).map((anhang: any) => ({ @@ -78,7 +86,11 @@ class EmailNotificationService extends AbstractNotificationProviderService { })), }); - this.logger_.info(`[mail] "${notification.template}" an ${notification.to} verschickt (${info.messageId}).`); + this.logger_.info( + `[mail] "${notification.template}" an ${notification.to}` + + (umgeleitet ? ` umgeleitet nach ${umgeleitet}` : "") + + ` verschickt (${info.messageId}).` + ); return { id: info.messageId }; } } diff --git a/compose.prod.yml b/compose.prod.yml index 6ce01ad..869354a 100644 --- a/compose.prod.yml +++ b/compose.prod.yml @@ -112,6 +112,9 @@ services: SMTP_USER: ${SMTP_USER:-} SMTP_PASSWORD: ${SMTP_PASSWORD:-} MAIL_FROM: ${MAIL_FROM:-} + # Auf dem Testsystem setzen: alle Mails gehen dann dorthin statt an + # Kunden. In der Produktion leer lassen. + MAIL_TEST_EMPFAENGER: ${MAIL_TEST_EMPFAENGER:-} volumes: - ${DATA_DIR:-/srv/place4bees}/uploads:/app/static ports: