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: