Testbetrieb: alle Mails an eine Adresse umleiten

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) <noreply@anthropic.com>
This commit is contained in:
torbinus
2026-10-26 10:21:24 +01:00
parent f4756998d9
commit 9f25f29b7f
4 changed files with 20 additions and 3 deletions
+1
View File
@@ -64,6 +64,7 @@ STORE_CORS=https://place4bees.com
ADMIN_CORS=https://place4bees.com ADMIN_CORS=https://place4bees.com
AUTH_CORS=https://place4bees.com AUTH_CORS=https://place4bees.com
GA_ID=<Messkennung, erst nach Einwilligungsbanner-Prüfung> GA_ID=<Messkennung, erst nach Einwilligungsbanner-Prüfung>
MAIL_TEST_EMPFAENGER=<LEER — sonst bekommen Kunden keine einzige Mail>
``` ```
**DHL umstellen** — beide Schalter, in dieser Reihenfolge: **DHL umstellen** — beide Schalter, in dieser Reihenfolge:
+1
View File
@@ -92,6 +92,7 @@ module.exports = defineConfig({
user: process.env.SMTP_USER, user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD, pass: process.env.SMTP_PASSWORD,
from: process.env.MAIL_FROM, from: process.env.MAIL_FROM,
testRecipient: process.env.MAIL_TEST_EMPFAENGER || undefined,
}, },
} }
: { : {
@@ -9,6 +9,11 @@ type Options = {
user?: string; user?: string;
pass?: string; pass?: string;
from: 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. // können, ohne die Adresse aus dem Text zu kopieren.
const antwortAn = (notification.data as any)?.reply_to; const antwortAn = (notification.data as any)?.reply_to;
const umgeleitet = this.options_.testRecipient;
const an = umgeleitet || notification.to;
const info = await this.transporter_.sendMail({ const info = await this.transporter_.sendMail({
from: notification.from || this.options_.from, from: notification.from || this.options_.from,
...(typeof antwortAn === "string" && antwortAn ? { replyTo: antwortAn } : {}), ...(typeof antwortAn === "string" && antwortAn ? { replyTo: antwortAn } : {}),
to: notification.to, to: an,
subject: content.subject, subject: umgeleitet ? `[TEST an ${notification.to}] ${content.subject}` : content.subject,
text: content.text, text: content.text,
html: content.html, html: content.html,
attachments: (notification.attachments ?? []).map((anhang: any) => ({ 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 }; return { id: info.messageId };
} }
} }
+3
View File
@@ -112,6 +112,9 @@ services:
SMTP_USER: ${SMTP_USER:-} SMTP_USER: ${SMTP_USER:-}
SMTP_PASSWORD: ${SMTP_PASSWORD:-} SMTP_PASSWORD: ${SMTP_PASSWORD:-}
MAIL_FROM: ${MAIL_FROM:-} 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: volumes:
- ${DATA_DIR:-/srv/place4bees}/uploads:/app/static - ${DATA_DIR:-/srv/place4bees}/uploads:/app/static
ports: ports: