Mails im Stil der Webseite
Alle Mails teilen sich einen Rahmen: Logo oben, honiggelber Balken "Direkt vom Imker · handabgefüllt in Hamburg", weiße Karte, dunkler Fuß. Überschriften in Bebas Neue, Fließtext Open Sans, Farben aus global.css. Tabellen und Inline-Stile, damit auch Outlook und Gmail sie richtig zeigen; ohne Webfonts (Gmail) fallen die Schriften auf Arial zurück. Das Logo hängt der Mailversand per CID an, sobald eine Mail es benutzt — nachladen würde hinter dem Passwortschutz des Testsystems nicht klappen und wird von vielen Programmen blockiert. Die Kontaktanfrage an den Shop nutzt jetzt denselben Rahmen. Neu: src/scripts/mail-muster.ts erzeugt alle 14 Mails mit Beispieldaten, als Vorschau oder (SENDEN=1) verschickt an eine Adresse. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { FARBE, RAHMEN, STIL } from "./order-emails";
|
||||
/**
|
||||
* Die Mail, die eine Anfrage aus einem Kontaktformular auslöst.
|
||||
*
|
||||
@@ -34,28 +35,23 @@ export function anfrageMail(anfrage: Anfrage) {
|
||||
...(seite ? [["Seite", seite] as [string, string]] : []),
|
||||
];
|
||||
|
||||
const html = `<!doctype html>
|
||||
<html lang="de"><head><meta charset="utf-8" /></head>
|
||||
<body style="margin:0;background:#f6f5f1;padding:24px;font-family:Arial,Helvetica,sans-serif;color:#1a1a1a;font-size:15px;line-height:1.55">
|
||||
<div style="max-width:600px;margin:0 auto;background:#ffffff;padding:32px">
|
||||
<h1 style="margin:0 0 20px;font-size:20px">Neue Anfrage über ${entschaerfen(quelle)}</h1>
|
||||
<table style="width:100%;border-collapse:collapse">
|
||||
const html = RAHMEN(`
|
||||
<h1 style="${STIL.h1}">Neue Anfrage über ${entschaerfen(quelle)}</h1>
|
||||
<table role="presentation" style="width:100%;border-collapse:collapse;margin:16px 0 0">
|
||||
${zeilen
|
||||
.map(
|
||||
([k, v]) => `<tr>
|
||||
<td style="padding:6px 12px 6px 0;color:#6b6b66;white-space:nowrap;vertical-align:top">${entschaerfen(k)}</td>
|
||||
<td style="padding:6px 12px 6px 0;color:${FARBE.text};white-space:nowrap;vertical-align:top">${entschaerfen(k)}</td>
|
||||
<td style="padding:6px 0">${entschaerfen(String(v))}</td>
|
||||
</tr>`
|
||||
)
|
||||
.join("")}
|
||||
</table>
|
||||
<h2 style="margin:24px 0 8px;font-size:16px">Nachricht</h2>
|
||||
<h2 style="${STIL.h2}">Nachricht</h2>
|
||||
<p style="margin:0;white-space:pre-wrap">${entschaerfen(nachricht)}</p>
|
||||
<p style="margin:28px 0 0;padding-top:16px;border-top:1px solid #dcdcd8;color:#6b6b66;font-size:13px">
|
||||
<p style="margin:28px 0 0;padding-top:16px;border-top:1px solid ${FARBE.linie};color:${FARBE.text};font-size:13px">
|
||||
Antworten geht direkt an ${entschaerfen(email)}.
|
||||
</p>
|
||||
</div>
|
||||
</body></html>`;
|
||||
</p>`);
|
||||
|
||||
const text = [
|
||||
`Neue Anfrage über ${quelle}`,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -10,6 +10,8 @@
|
||||
* Feldauswahl abweichende Werte (siehe Kommentar in invoice-handler.ts).
|
||||
*/
|
||||
|
||||
import { MAIL_LOGO_CID } from "./mail-logo";
|
||||
|
||||
const SHOP = {
|
||||
name: "PLACE4BEES GmbH",
|
||||
web: "www.place4bees.com",
|
||||
@@ -96,15 +98,64 @@ function adressblock(adresse: Record<string, any> | null): string[] {
|
||||
].filter(Boolean) as string[];
|
||||
}
|
||||
|
||||
const RAHMEN = (inhalt: string) => `<!doctype html>
|
||||
<html lang="de"><head><meta charset="utf-8" /></head>
|
||||
<body style="margin:0;background:#f6f5f1;padding:24px;font-family:Arial,Helvetica,sans-serif;color:#1a1a1a;font-size:15px;line-height:1.55">
|
||||
<div style="max-width:600px;margin:0 auto;background:#ffffff;padding:32px">
|
||||
/*
|
||||
* Gestaltung wie die Webseite: Farben aus frontend/src/styles/global.css,
|
||||
* Überschriften in Bebas Neue, Fließtext in Open Sans. Programme ohne
|
||||
* Webfonts (z. B. Gmail) fallen auf Arial zurück.
|
||||
*
|
||||
* Tabellen statt div/flex, alle Stile inline: so stellen auch Outlook und
|
||||
* Gmail die Mail richtig dar.
|
||||
*/
|
||||
export const FARBE = {
|
||||
honig: "#f8ac11",
|
||||
honigTinte: "#8a5e05",
|
||||
honigHell: "#fdf3dc",
|
||||
tinte: "#212326",
|
||||
text: "#5b6068",
|
||||
textLeise: "#8b9099",
|
||||
linie: "#e3e5e9",
|
||||
flaeche: "#f2f3f5",
|
||||
};
|
||||
const SCHRIFT = "'Open Sans',Arial,Helvetica,sans-serif";
|
||||
const DISPLAY = "'Bebas Neue','Arial Narrow',Arial,Helvetica,sans-serif";
|
||||
|
||||
/** Stile, die in allen Vorlagen gleich aussehen sollen. */
|
||||
export const STIL = {
|
||||
h1: `margin:0 0 6px;font-family:${DISPLAY};font-weight:normal;font-size:36px;line-height:1.1;letter-spacing:0.5px;text-transform:uppercase;color:${FARBE.tinte}`,
|
||||
h2: `margin:28px 0 8px;font-family:${DISPLAY};font-weight:normal;font-size:22px;line-height:1.2;letter-spacing:0.5px;text-transform:uppercase;color:${FARBE.tinte}`,
|
||||
kasten: `margin:20px 0 0;padding:14px 16px;background:${FARBE.honigHell};border-left:3px solid ${FARBE.honig};border-radius:4px`,
|
||||
link: `color:${FARBE.honigTinte};text-decoration:underline`,
|
||||
knopf: `display:inline-block;background:${FARBE.honig};color:${FARBE.tinte};text-decoration:none;font-weight:bold;padding:13px 26px;border-radius:6px`,
|
||||
};
|
||||
|
||||
export const RAHMEN = (inhalt: string) => `<!doctype html>
|
||||
<html lang="de"><head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Open+Sans:wght@400;700&display=swap" rel="stylesheet" />
|
||||
</head>
|
||||
<body style="margin:0;padding:0;background:${FARBE.flaeche}">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:${FARBE.flaeche}">
|
||||
<tr><td align="center" style="padding:28px 12px">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:600px;background:#ffffff;border-radius:10px;overflow:hidden">
|
||||
<tr><td align="center" style="padding:28px 24px 22px">
|
||||
<img src="cid:${MAIL_LOGO_CID}" width="140" height="110" alt="place4bees — Hamburger Stadtimkerei" style="display:block;border:0" />
|
||||
</td></tr>
|
||||
<tr><td align="center" style="background:${FARBE.honig};padding:9px 16px;font-family:${SCHRIFT};font-size:11px;font-weight:bold;letter-spacing:1.6px;text-transform:uppercase;color:${FARBE.tinte}">
|
||||
Direkt vom Imker · handabgefüllt in Hamburg
|
||||
</td></tr>
|
||||
<tr><td style="padding:36px 36px 32px;font-family:${SCHRIFT};font-size:15px;line-height:1.6;color:${FARBE.tinte}">
|
||||
${inhalt}
|
||||
<p style="margin:32px 0 0;padding-top:20px;border-top:1px solid #dcdcd8;color:#6b6b66;font-size:13px">
|
||||
${SHOP.name} · ${SHOP.web} · <a href="mailto:${SHOP.email}" style="color:#8a5e05">${SHOP.email}</a>
|
||||
</p>
|
||||
</div>
|
||||
</td></tr>
|
||||
<tr><td style="background:${FARBE.tinte};padding:24px 36px;font-family:${SCHRIFT};font-size:12px;line-height:1.7;color:#c9ccd1">
|
||||
<span style="font-family:${DISPLAY};font-size:18px;letter-spacing:1px;color:#ffffff">PLACE<span style="color:${FARBE.honig}">4</span>BEES</span><br />
|
||||
${SHOP.name} · Hamburger Stadtimkerei<br />
|
||||
<a href="https://${SHOP.web}" style="color:#ffffff;text-decoration:none">${SHOP.web}</a> ·
|
||||
<a href="mailto:${SHOP.email}" style="color:#ffffff;text-decoration:none">${SHOP.email}</a>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</body></html>`;
|
||||
|
||||
function postenTabelle(bestellung: MailBestellung): string {
|
||||
@@ -113,12 +164,12 @@ function postenTabelle(bestellung: MailBestellung): string {
|
||||
const zeilen = posten
|
||||
.map(
|
||||
(p) => `<tr>
|
||||
<td style="padding:8px 0;border-bottom:1px solid #eeeeea">${p.quantity} × ${p.title}${
|
||||
<td style="padding:8px 0;border-bottom:1px solid ${FARBE.linie}">${p.quantity} × ${p.title}${
|
||||
p.hinweis
|
||||
? `<br /><span style="color:#6b6b66;font-size:13px">${p.hinweis}</span>`
|
||||
? `<br /><span style="color:${FARBE.text};font-size:13px">${p.hinweis}</span>`
|
||||
: ""
|
||||
}</td>
|
||||
<td style="padding:8px 0;border-bottom:1px solid #eeeeea;text-align:right;white-space:nowrap">${euro(p.gesamt, w)}</td>
|
||||
<td style="padding:8px 0;border-bottom:1px solid ${FARBE.linie};text-align:right;white-space:nowrap">${euro(p.gesamt, w)}</td>
|
||||
</tr>`
|
||||
)
|
||||
.join("");
|
||||
@@ -131,8 +182,8 @@ function postenTabelle(bestellung: MailBestellung): string {
|
||||
: ""
|
||||
}
|
||||
<tr>
|
||||
<td style="padding:10px 0 0;border-top:1px solid #dcdcd8;font-weight:bold">Gesamt</td>
|
||||
<td style="padding:10px 0 0;border-top:1px solid #dcdcd8;text-align:right;font-weight:bold">${euro(gesamt, w)}</td>
|
||||
<td style="padding:10px 0 0;border-top:1px solid ${FARBE.linie};font-weight:bold">Gesamt</td>
|
||||
<td style="padding:10px 0 0;border-top:1px solid ${FARBE.linie};text-align:right;font-weight:bold">${euro(gesamt, w)}</td>
|
||||
</tr>
|
||||
${
|
||||
abzug > 0
|
||||
@@ -148,7 +199,7 @@ function postenTabelle(bestellung: MailBestellung): string {
|
||||
: ""
|
||||
}
|
||||
</table>
|
||||
<p style="margin:10px 0 0;color:#6b6b66;font-size:13px">Alle Preise inklusive Umsatzsteuer.</p>`;
|
||||
<p style="margin:10px 0 0;color:${FARBE.text};font-size:13px">Alle Preise inklusive Umsatzsteuer.</p>`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,18 +243,18 @@ export function bestellbestaetigung(bestellung: MailBestellung) {
|
||||
: einleitungZeilen.join("\n ");
|
||||
|
||||
const html = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">${ueberschrift}</h1>
|
||||
<p style="margin:0;color:#6b6b66">Bestellnummer ${bestellung.display_id}</p>
|
||||
<h1 style="${STIL.h1}">${ueberschrift}</h1>
|
||||
<p style="margin:0;color:${FARBE.text}">Bestellnummer ${bestellung.display_id}</p>
|
||||
<p style="margin:24px 0 0">${anrede(bestellung.shipping_address)}</p>
|
||||
<p style="margin:12px 0 0">${einleitung}</p>
|
||||
${postenTabelle(bestellung)}
|
||||
${
|
||||
adresse.length
|
||||
? `<h2 style="margin:28px 0 6px;font-size:16px">${nurDigital ? "Rechnungsadresse" : "Lieferadresse"}</h2>
|
||||
<p style="margin:0;color:#4a4a45">${adresse.join("<br />")}</p>`
|
||||
? `<h2 style="${STIL.h2}">${nurDigital ? "Rechnungsadresse" : "Lieferadresse"}</h2>
|
||||
<p style="margin:0;color:${FARBE.text}">${adresse.join("<br />")}</p>`
|
||||
: ""
|
||||
}
|
||||
<p style="margin:28px 0 0;color:#6b6b66;font-size:13px">
|
||||
<p style="margin:28px 0 0;color:${FARBE.text};font-size:13px">
|
||||
Diese E-Mail bestätigt den Eingang Ihrer Bestellung. Die Rechnung liegt
|
||||
als PDF bei. Ihr Widerrufsrecht und die Bedingungen finden Sie unter
|
||||
${SHOP.web}.
|
||||
@@ -262,7 +313,7 @@ export function versandnachricht(bestellung: MailBestellung, sendungen: Sendung[
|
||||
(s) => `<li style="margin:0 0 6px">
|
||||
<strong>${s.tracking_number}</strong>${
|
||||
s.tracking_url
|
||||
? ` — <a href="${s.tracking_url}" style="color:#8a5e05">Sendung verfolgen</a>`
|
||||
? ` — <a href="${s.tracking_url}" style="${STIL.link}">Sendung verfolgen</a>`
|
||||
: ""
|
||||
}
|
||||
</li>`
|
||||
@@ -270,15 +321,15 @@ export function versandnachricht(bestellung: MailBestellung, sendungen: Sendung[
|
||||
.join("");
|
||||
|
||||
const html = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">Ihre Bestellung ist unterwegs</h1>
|
||||
<p style="margin:0;color:#6b6b66">Bestellnummer ${bestellung.display_id}</p>
|
||||
<h1 style="${STIL.h1}">Ihre Bestellung ist unterwegs</h1>
|
||||
<p style="margin:0;color:${FARBE.text}">Bestellnummer ${bestellung.display_id}</p>
|
||||
<p style="margin:24px 0 0">${anrede(bestellung.shipping_address)}</p>
|
||||
<p style="margin:12px 0 0">
|
||||
wir haben Ihr Paket verpackt und ${versandart ? `mit ${versandart} ` : ""}auf den Weg gebracht.
|
||||
</p>
|
||||
<h2 style="margin:24px 0 8px;font-size:16px">Sendungsnummer</h2>
|
||||
<h2 style="${STIL.h2}">Sendungsnummer</h2>
|
||||
<ul style="margin:0;padding-left:18px">${nummern}</ul>
|
||||
<p style="margin:16px 0 0;padding:12px 14px;background:#faf6ec">
|
||||
<p style="${STIL.kasten}">
|
||||
<strong>Stand:</strong> Sendung angemeldet — das Paket ist beim
|
||||
Versanddienstleister eingebucht. Bis zur ersten Statusmeldung in der
|
||||
Verfolgung können einige Stunden vergehen.
|
||||
@@ -327,7 +378,7 @@ export function geschenkAnkuendigung(abo: GeschenkAbo) {
|
||||
const umfang = `${abo.lieferungen} Lieferungen, ${abo.rhythmus}${abo.groesse ? `, je ${abo.groesse}` : ""}`;
|
||||
|
||||
const html = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">Für Sie: ein Honig-Abo</h1>
|
||||
<h1 style="${STIL.h1}">Für Sie: ein Honig-Abo</h1>
|
||||
<p style="margin:24px 0 0">Hallo ${abo.empfaengerName},</p>
|
||||
<p style="margin:12px 0 0">
|
||||
${von} ein Honig-Abo von place4bees — ${umfang}. Der Honig kommt aus
|
||||
@@ -337,7 +388,7 @@ export function geschenkAnkuendigung(abo: GeschenkAbo) {
|
||||
Sie müssen nichts tun. Die erste Sendung ist schon unterwegs, und zu
|
||||
jedem weiteren Paket schicken wir Ihnen die Sendungsnummer.
|
||||
</p>
|
||||
<p style="margin:24px 0 0;color:#6b6b66;font-size:13px">
|
||||
<p style="margin:24px 0 0;color:${FARBE.text};font-size:13px">
|
||||
Stimmt die Lieferadresse nicht oder passt der Zeitpunkt nicht?
|
||||
Schreiben Sie uns einfach.
|
||||
</p>`);
|
||||
@@ -392,7 +443,7 @@ export function kuendigungsbestaetigung(k: Kuendigung) {
|
||||
if (k.grund) zeilen.push(["Grund", k.grund]);
|
||||
|
||||
const htmlInhalt = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">Ihre Kündigung ist eingegangen</h1>
|
||||
<h1 style="${STIL.h1}">Ihre Kündigung ist eingegangen</h1>
|
||||
<p style="margin:24px 0 0">Hallo,</p>
|
||||
<p style="margin:12px 0 0">
|
||||
hiermit bestätigen wir den Eingang Ihrer Kündigung. Ihr Abo endet
|
||||
@@ -402,13 +453,13 @@ export function kuendigungsbestaetigung(k: Kuendigung) {
|
||||
${zeilen
|
||||
.map(
|
||||
([feld, wert]) => `<tr>
|
||||
<td style="padding:6px 12px 6px 0;color:#6b6b66;vertical-align:top;white-space:nowrap">${feld}</td>
|
||||
<td style="padding:6px 12px 6px 0;color:${FARBE.text};vertical-align:top;white-space:nowrap">${feld}</td>
|
||||
<td style="padding:6px 0">${html(wert)}</td>
|
||||
</tr>`
|
||||
)
|
||||
.join("")}
|
||||
</table>
|
||||
<p style="margin:24px 0 0;color:#6b6b66;font-size:13px">
|
||||
<p style="margin:24px 0 0;color:${FARBE.text};font-size:13px">
|
||||
Bewahren Sie diese E-Mail als Nachweis auf. War die Kündigung ein
|
||||
Versehen? Schreiben Sie uns einfach.
|
||||
</p>`);
|
||||
@@ -434,18 +485,18 @@ export function kuendigungsbestaetigung(k: Kuendigung) {
|
||||
/** Eine Mail mit genau einem Knopf — für Bestätigungs- und Zurücksetzen-Links. */
|
||||
function linkMail(k: { titel: string; absatz: string; knopf: string; link: string; hinweis: string }) {
|
||||
const htmlInhalt = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">${k.titel}</h1>
|
||||
<h1 style="${STIL.h1}">${k.titel}</h1>
|
||||
<p style="margin:24px 0 0">Hallo,</p>
|
||||
<p style="margin:12px 0 0">${k.absatz}</p>
|
||||
<p style="margin:24px 0 0">
|
||||
<a href="${html(k.link)}" style="display:inline-block;background:#f2a900;color:#1a1a1a;text-decoration:none;font-weight:bold;padding:12px 22px;border-radius:6px">${k.knopf}</a>
|
||||
<a href="${html(k.link)}" style="${STIL.knopf}">${k.knopf}</a>
|
||||
</p>
|
||||
<p style="margin:16px 0 0;color:#6b6b66;font-size:13px">
|
||||
<p style="margin:16px 0 0;color:${FARBE.text};font-size:13px">
|
||||
Der Link gilt 15 Minuten. Funktioniert der Knopf nicht, kopieren Sie
|
||||
diese Adresse in Ihren Browser:<br />
|
||||
<span style="word-break:break-all">${html(k.link)}</span>
|
||||
</p>
|
||||
<p style="margin:16px 0 0;color:#6b6b66;font-size:13px">${k.hinweis}</p>`);
|
||||
<p style="margin:16px 0 0;color:${FARBE.text};font-size:13px">${k.hinweis}</p>`);
|
||||
|
||||
const text = [
|
||||
k.titel,
|
||||
@@ -504,7 +555,7 @@ export function geschenkVersandnachricht(
|
||||
const nummern = sendungen
|
||||
.map(
|
||||
(s) => `<li style="margin:0 0 6px"><strong>${s.tracking_number}</strong>${
|
||||
s.tracking_url ? ` — <a href="${s.tracking_url}" style="color:#8a5e05">Sendung verfolgen</a>` : ""
|
||||
s.tracking_url ? ` — <a href="${s.tracking_url}" style="${STIL.link}">Sendung verfolgen</a>` : ""
|
||||
}</li>`
|
||||
)
|
||||
.join("");
|
||||
@@ -515,16 +566,16 @@ export function geschenkVersandnachricht(
|
||||
: "Das war die letzte Lieferung Ihres Abos.";
|
||||
|
||||
const html = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">Ihr Honig ist unterwegs</h1>
|
||||
<h1 style="${STIL.h1}">Ihr Honig ist unterwegs</h1>
|
||||
<p style="margin:24px 0 0">Hallo ${empfaengerName},</p>
|
||||
<p style="margin:12px 0 0">die nächste Lieferung Ihres Honig-Abos ist auf dem Weg.</p>
|
||||
<h2 style="margin:24px 0 8px;font-size:16px">Im Paket</h2>
|
||||
<h2 style="${STIL.h2}">Im Paket</h2>
|
||||
<ul style="margin:0;padding-left:18px">
|
||||
${posten.map((p) => `<li style="margin:0 0 4px">${p.quantity} × ${p.title}</li>`).join("")}
|
||||
</ul>
|
||||
<h2 style="margin:24px 0 8px;font-size:16px">Sendungsnummer</h2>
|
||||
<h2 style="${STIL.h2}">Sendungsnummer</h2>
|
||||
<ul style="margin:0;padding-left:18px">${nummern}</ul>
|
||||
<p style="margin:16px 0 0;padding:12px 14px;background:#faf6ec">
|
||||
<p style="${STIL.kasten}">
|
||||
<strong>Stand:</strong> Sendung angemeldet — das Paket ist beim
|
||||
Versanddienstleister eingebucht. ${rest}
|
||||
</p>`);
|
||||
@@ -578,21 +629,21 @@ export function patenschaftAnkuendigung(geschenk: PatenschaftGeschenk) {
|
||||
];
|
||||
|
||||
const html = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">Für Sie: eine Bienenpatenschaft</h1>
|
||||
<h1 style="${STIL.h1}">Für Sie: eine Bienenpatenschaft</h1>
|
||||
<p style="margin:24px 0 0">Hallo ${geschenk.name},</p>
|
||||
<p style="margin:12px 0 0">
|
||||
${von} eine Bienenpatenschaft bei place4bees. Ein Volk in Hamburg trägt
|
||||
von jetzt an Ihren Namen — auf der Urkunde und auf dem Etikett der Gläser.
|
||||
</p>
|
||||
<h2 style="margin:24px 0 8px;font-size:16px">Was dazugehört</h2>
|
||||
<h2 style="${STIL.h2}">Was dazugehört</h2>
|
||||
<ul style="margin:0;padding-left:18px">
|
||||
${leistungen.map((l) => `<li style="margin:0 0 5px">${l}</li>`).join("")}
|
||||
</ul>
|
||||
<p style="margin:20px 0 0;padding:12px 14px;background:#faf6ec">
|
||||
<p style="${STIL.kasten}">
|
||||
Geerntet wird zweimal im Jahr. Ihren eigenen Honig bekommen Sie am Ende
|
||||
der Bienensaison, im Oktober oder November.
|
||||
</p>
|
||||
<p style="margin:24px 0 0;color:#6b6b66;font-size:13px">
|
||||
<p style="margin:24px 0 0;color:${FARBE.text};font-size:13px">
|
||||
Sie müssen nichts tun. Fragen beantworten wir gern — einfach antworten.
|
||||
</p>`);
|
||||
|
||||
@@ -647,23 +698,23 @@ export function gutscheinMail(g: GutscheinInhalt) {
|
||||
];
|
||||
|
||||
const inhalt = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">${g.geschenk ? "Für Sie: ein Gutschein" : "Ihr Gutschein"}</h1>
|
||||
<h1 style="${STIL.h1}">${g.geschenk ? "Für Sie: ein Gutschein" : "Ihr Gutschein"}</h1>
|
||||
<p style="margin:24px 0 0">${html(hallo)}</p>
|
||||
<p style="margin:12px 0 0">${html(einleitung)}</p>
|
||||
${
|
||||
g.nachricht
|
||||
? `<p style="margin:16px 0 0;padding:12px 14px;background:#faf6ec;white-space:pre-line">${html(g.nachricht)}</p>`
|
||||
? `<p style="${STIL.kasten};white-space:pre-line">${html(g.nachricht)}</p>`
|
||||
: ""
|
||||
}
|
||||
<div style="margin:24px 0 0;padding:20px;border:2px dashed #f8ac11;text-align:center">
|
||||
<p style="margin:0;color:#6b6b66;font-size:13px">Gutscheincode</p>
|
||||
<p style="margin:0;color:${FARBE.text};font-size:13px">Gutscheincode</p>
|
||||
<p style="margin:6px 0 0;font-family:'Courier New',Courier,monospace;font-size:24px;font-weight:bold;letter-spacing:2px">${html(g.code)}</p>
|
||||
<p style="margin:6px 0 0;font-size:16px">Wert: ${betrag}</p>
|
||||
</div>
|
||||
<h2 style="margin:24px 0 8px;font-size:16px">So lösen Sie ihn ein</h2>
|
||||
<h2 style="${STIL.h2}">So lösen Sie ihn ein</h2>
|
||||
${einloesen.map((satz) => `<p style="margin:0 0 8px">${satz}</p>`).join("")}
|
||||
<p style="margin:16px 0 0"><a href="https://${SHOP.web}/shop" style="color:#8a5e05">Zum Shop</a></p>
|
||||
<p style="margin:24px 0 0;color:#6b6b66;font-size:13px">
|
||||
<p style="margin:16px 0 0"><a href="https://${SHOP.web}/shop" style="${STIL.link}">Zum Shop</a></p>
|
||||
<p style="margin:24px 0 0;color:${FARBE.text};font-size:13px">
|
||||
Bewahren Sie diese E-Mail gut auf: Wer den Code kennt, kann das Guthaben
|
||||
einlösen. Eine Barauszahlung ist nicht möglich.
|
||||
</p>`);
|
||||
@@ -715,7 +766,7 @@ export function gutscheinVersendetMail(g: GutscheinVersendet) {
|
||||
const hallo = g.kaeuferName ? `Hallo ${g.kaeuferName},` : "Hallo,";
|
||||
|
||||
const inhalt = RAHMEN(`
|
||||
<h1 style="margin:0 0 4px;font-size:22px">Ihr Gutschein ist verschickt</h1>
|
||||
<h1 style="${STIL.h1}">Ihr Gutschein ist verschickt</h1>
|
||||
<p style="margin:24px 0 0">${html(hallo)}</p>
|
||||
<p style="margin:12px 0 0">
|
||||
Ihre Zahlung ist eingegangen. Den Gutschein über ${betrag} haben wir eben
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AbstractNotificationProviderService, MedusaError } from "@medusajs/framework/utils";
|
||||
import type { ProviderSendNotificationDTO } from "@medusajs/framework/types";
|
||||
import nodemailer, { type Transporter } from "nodemailer";
|
||||
import { MAIL_LOGO_CID, MAIL_LOGO_PNG_BASE64 } from "../../lib/mail-logo";
|
||||
|
||||
type Options = {
|
||||
host: string;
|
||||
@@ -79,11 +80,25 @@ class EmailNotificationService extends AbstractNotificationProviderService {
|
||||
subject: umgeleitet ? `[TEST an ${notification.to}] ${content.subject}` : content.subject,
|
||||
text: content.text,
|
||||
html: content.html,
|
||||
attachments: (notification.attachments ?? []).map((anhang: any) => ({
|
||||
attachments: [
|
||||
...(notification.attachments ?? []).map((anhang: any) => ({
|
||||
filename: anhang.filename,
|
||||
content: Buffer.from(anhang.content, "base64"),
|
||||
contentType: anhang.content_type,
|
||||
})),
|
||||
// Der Rahmen aller Mails verweist auf das Logo per CID. Hier
|
||||
// angehängt, damit nicht jeder Subscriber daran denken muss.
|
||||
...(content.html?.includes(`cid:${MAIL_LOGO_CID}`)
|
||||
? [
|
||||
{
|
||||
filename: "place4bees.png",
|
||||
content: Buffer.from(MAIL_LOGO_PNG_BASE64, "base64"),
|
||||
contentType: "image/png",
|
||||
cid: MAIL_LOGO_CID,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
|
||||
this.logger_.info(
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Alle Mails, die der Shop verschicken kann, mit Beispieldaten — um nach
|
||||
* einer Änderung an Text oder Gestaltung alles auf einmal anzusehen.
|
||||
*
|
||||
* npx medusa exec ./src/scripts/mail-muster.ts
|
||||
* schreibt HTML-Vorschauen nach VORSCHAU_DIR (Standard: Temp-Ordner)
|
||||
* SENDEN=1 MUSTER_AN=shop@place4bees.com npx medusa exec ./src/scripts/mail-muster.ts
|
||||
* verschickt alle Muster an diese Adresse
|
||||
*
|
||||
* Die Rechnung als PDF-Anhang fehlt in den Mustern, sie hängt an einer
|
||||
* echten Bestellung.
|
||||
*/
|
||||
import { Modules } from "@medusajs/framework/utils";
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import {
|
||||
bestellbestaetigung,
|
||||
versandnachricht,
|
||||
geschenkAnkuendigung,
|
||||
geschenkVersandnachricht,
|
||||
patenschaftAnkuendigung,
|
||||
gutscheinMail,
|
||||
gutscheinVersendetMail,
|
||||
kuendigungsbestaetigung,
|
||||
emailBestaetigenMail,
|
||||
passwortZuruecksetzenMail,
|
||||
} from "../lib/order-emails";
|
||||
import { anfrageMail } from "../lib/contact-email";
|
||||
import { MAIL_LOGO_PNG_BASE64 } from "../lib/mail-logo";
|
||||
|
||||
const adresse = {
|
||||
first_name: "Erika",
|
||||
last_name: "Mustermann",
|
||||
address_1: "Musterstraße 12",
|
||||
postal_code: "20095",
|
||||
city: "Hamburg",
|
||||
country_code: "de",
|
||||
};
|
||||
const basis = {
|
||||
display_id: 1042,
|
||||
email: "erika@example.com",
|
||||
created_at: new Date(),
|
||||
currency_code: "eur",
|
||||
shipping_address: adresse,
|
||||
shipping_methods: [{ name: "DHL Paket", amount: 5.49 }],
|
||||
};
|
||||
const sendung = [{ tracking_number: "00340434333010200291286", tracking_url: "https://www.dhl.de/de/privatkunden/pakete-empfangen/verfolgen.html" }];
|
||||
|
||||
const muster: [string, { subject: string; html: string; text: string }][] = [
|
||||
["Bestellbestätigung", bestellbestaetigung({
|
||||
...basis,
|
||||
items: [
|
||||
{ title: "Lindenhonig aus Hamburg – cremig, 250 g", quantity: 2, unit_price: 6.9 },
|
||||
{ title: "Bienenpatenschaft", quantity: 1, unit_price: 49, hinweis: "Urkunde und Etikett auf: Familie Mustermann" },
|
||||
],
|
||||
gutscheine: [{ code: "P4B-…-7K2Q", betrag: 10 }],
|
||||
})],
|
||||
["Bestellbestätigung Abo-Lieferung", bestellbestaetigung({
|
||||
...basis,
|
||||
aus_abo: true,
|
||||
items: [{ title: "Frühlingsblütenhonig aus Hamburg – cremig, 250 g", quantity: 1, unit_price: 6.9 }],
|
||||
})],
|
||||
["Bestellbestätigung nur Gutschein", bestellbestaetigung({
|
||||
...basis,
|
||||
shipping_methods: [],
|
||||
items: [{ title: "Geschenkgutschein 25 €", quantity: 1, unit_price: 25, digital: true }],
|
||||
})],
|
||||
["Versandnachricht", versandnachricht(
|
||||
{ ...basis, items: [{ title: "Lindenhonig aus Hamburg – cremig, 250 g", quantity: 2, unit_price: 6.9 }] },
|
||||
sendung
|
||||
)],
|
||||
["Geschenk-Abo: Ankündigung an Beschenkte", geschenkAnkuendigung({
|
||||
empfaengerName: "Max Beispiel", schenkerName: "Erika", lieferungen: 6, rhythmus: "monatlich", groesse: "250 Gramm",
|
||||
})],
|
||||
["Geschenk-Abo: Versandnachricht an Beschenkte", geschenkVersandnachricht(
|
||||
"Max Beispiel",
|
||||
[{ title: "Heidehonig aus der Lüneburger Heide, 250 g", quantity: 1, unit_price: 0 }],
|
||||
sendung,
|
||||
4
|
||||
)],
|
||||
["Patenschaft: Ankündigung", patenschaftAnkuendigung({ name: "Familie Mustermann", schenkerName: "Erika" })],
|
||||
["Gutschein (für sich selbst)", gutscheinMail({
|
||||
code: "P4B-ABCD-EFGH-7K2Q", betrag: 25, waehrung: "eur", empfaengerName: "Erika Mustermann",
|
||||
schenkerName: null, nachricht: null, geschenk: false,
|
||||
})],
|
||||
["Gutschein (als Geschenk)", gutscheinMail({
|
||||
code: "P4B-WXYZ-1234-9M3P", betrag: 50, waehrung: "eur", empfaengerName: "Max Beispiel",
|
||||
schenkerName: "Erika", nachricht: "Alles Gute zum Geburtstag!\nLass es dir schmecken.", geschenk: true,
|
||||
})],
|
||||
["Gutschein verschickt (an Käuferin)", gutscheinVersendetMail({
|
||||
code: "P4B-WXYZ-1234-9M3P", betrag: 50, waehrung: "eur", empfaengerEmail: "max@example.com",
|
||||
empfaengerName: "Max Beispiel", kaeuferName: "Erika Mustermann",
|
||||
})],
|
||||
["Kündigungsbestätigung", kuendigungsbestaetigung({
|
||||
aboId: "sub_01M5VQ7H8DG80ZTY4CF08ECTDM", art: "Ordentliche Kündigung", eingegangen: new Date(),
|
||||
rhythmus: "monatlich", groesse: "250 Gramm", name: "Erika Mustermann", grund: "Zu viel Honig im Schrank",
|
||||
})],
|
||||
["E-Mail bestätigen", emailBestaetigenMail("https://place4bees.com/konto/bestaetigen?code=MUSTER")],
|
||||
["Passwort zurücksetzen", passwortZuruecksetzenMail("https://place4bees.com/konto/passwort-neu?token=MUSTER")],
|
||||
["Kontaktanfrage (intern)", anfrageMail({
|
||||
name: "Erika Mustermann", email: "erika@example.com", quelle: "Ihr Projekt", seite: "/business/kontakt",
|
||||
nachricht: "Hallo,\nwir würden gern zwei Bienenvölker auf unserem Firmendach aufstellen. Wie läuft das ab?\n\nViele Grüße",
|
||||
})],
|
||||
];
|
||||
|
||||
export default async function ({ container }: any) {
|
||||
const logger = container.resolve("logger");
|
||||
const senden = process.env.SENDEN === "1";
|
||||
const an = process.env.MUSTER_AN ?? "shop@place4bees.com";
|
||||
const dir = process.env.VORSCHAU_DIR ?? path.join(os.tmpdir(), "mail-muster");
|
||||
if (!senden) fs.mkdirSync(dir, { recursive: true });
|
||||
|
||||
for (const [i, [name, mail]] of muster.entries()) {
|
||||
const nr = String(i + 1).padStart(2, "0");
|
||||
if (!senden) {
|
||||
// In der Vorschau das Logo direkt einbetten, das CID gibt es nur in der Mail.
|
||||
const vorschau = mail.html.replace("cid:p4b-logo", `data:image/png;base64,${MAIL_LOGO_PNG_BASE64}`);
|
||||
fs.writeFileSync(path.join(dir, `${nr}.html`), vorschau);
|
||||
continue;
|
||||
}
|
||||
await container.resolve(Modules.NOTIFICATION).createNotifications({
|
||||
to: an,
|
||||
channel: "email",
|
||||
template: `muster-${nr}`,
|
||||
content: { ...mail, subject: `[Muster ${nr}/${muster.length}] ${name} — ${mail.subject}` },
|
||||
});
|
||||
logger.info(`MUSTER ${nr} verschickt: ${name}`);
|
||||
}
|
||||
if (!senden) {
|
||||
fs.writeFileSync(
|
||||
path.join(dir, "index.html"),
|
||||
`<meta charset="utf-8"><body style="font-family:sans-serif;padding:20px">` +
|
||||
muster.map(([name], i) => `<p><a href="${String(i + 1).padStart(2, "0")}.html">${i + 1}. ${name}</a></p>`).join("")
|
||||
);
|
||||
console.log(`VORSCHAU ${muster.length} Mails in ${dir}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user