E-mails HTML aux couleurs du site vitrine

Gabarit commun (src/mail/email-layout.ts) : fond sable, carte blanche,
titre fort, bouton vert, récapitulatif, encadré, pied de page sombre ;
tableaux et styles en ligne pour Gmail/Outlook/Apple Mail, logos PNG
hébergés sur monespacepro.eu/assets. Appliqué aux e-mails carte client,
lien d'abonnement, facture et demande de démo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tony AVERTY 2026-10-07 09:23:35 +02:00
parent f6bd030b35
commit 4be2fdfad2
6 changed files with 218 additions and 7 deletions

View file

@ -6,7 +6,7 @@ import { join } from 'path';
import Stripe from 'stripe';
import { PrismaService } from '../prisma/prisma.service';
import { MailService } from '../mail/mail.service';
import { escapeHtml } from '../enrollment/pages';
import { emailLayout, esc } from '../mail/email-layout';
import { renderInvoicePdf } from './invoice-pdf';
/** Factures PDF : hors des dossiers servis publiquement. */
@ -121,7 +121,24 @@ export class BillingService {
if (sendEmail) {
const text = `Bonjour ${store.contactName},\n\nVoici le lien pour activer l'abonnement MonEspacePro de ${store.name} (10 € par mois, sans engagement, carte bancaire ou prélèvement SEPA) :\n${session.url}\n\nCe lien est valable 24 heures.\n\nMonEspacePro`;
const html = `<p>Bonjour ${escapeHtml(store.contactName)},</p><p>Voici le lien pour activer l'abonnement MonEspacePro de <strong>${escapeHtml(store.name)}</strong> : 10 € par mois, sans engagement, par carte bancaire ou prélèvement SEPA.</p><p><a href="${escapeHtml(session.url!)}">Activer mon abonnement</a></p><p>Ce lien est valable 24 heures.</p><p>MonEspacePro</p>`;
const html = emailLayout({
webUrl,
preheader: `Activez l'abonnement MonEspacePro de ${store.name} en quelques clics.`,
eyebrow: 'Abonnement',
title: `Activez MonEspacePro pour ${store.name}`,
paragraphs: [
`Bonjour ${esc(store.contactName)},`,
`Votre carte de fidélité est prête. Il ne reste qu'à activer l'abonnement de <strong>${esc(store.name)}</strong> pour l'ouvrir à vos clients.`,
],
cta: { label: 'Activer mon abonnement', url: session.url! },
details: [
['Formule', 'Carte de fidélité dématérialisée, 1 magasin'],
['Prix', '10 € par mois — TVA non applicable, art. 293 B du CGI'],
['Engagement', 'Aucun, résiliable à tout moment'],
['Paiement', 'Carte bancaire ou prélèvement SEPA, factures automatiques'],
],
note: 'Ce lien est valable 24 heures. Passé ce délai, demandez-nous simplement un nouveau lien.',
});
await this.mail.send(store.contactEmail, `Activez l'abonnement MonEspacePro de ${store.name}`, text, html);
}
return { url: session.url, expiresAt: new Date(session.expires_at * 1000), emailedTo: sendEmail ? store.contactEmail : null };
@ -258,8 +275,26 @@ export class BillingService {
const pdf = await this.renderPdf(invoice.id);
const text = `Bonjour ${store.contactName},\n\nVeuillez trouver ci-joint la facture ${invoice.number} de ${euros(invoice.amountCents)} pour l'abonnement MonEspacePro de ${store.name}. Elle a été réglée le ${paidAt.toLocaleDateString('fr-FR')}.\n\nMerci de votre confiance,\nMonEspacePro`;
const day = (d: Date) => d.toLocaleDateString('fr-FR', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'Europe/Paris' });
const html = emailLayout({
webUrl: this.config.get('webUrl')!,
preheader: `Facture ${invoice.number} — ${euros(invoice.amountCents)}, réglée.`,
eyebrow: 'Facture',
title: 'Merci, votre paiement est bien reçu',
paragraphs: [
`Bonjour ${esc(store.contactName)},`,
`Vous trouverez en pièce jointe la facture <strong>${esc(invoice.number)}</strong> pour l'abonnement MonEspacePro de ${esc(store.name)}.`,
],
details: [
['Facture', esc(invoice.number)],
['Montant', `${euros(invoice.amountCents)} — TVA non applicable, art. 293 B du CGI`],
['Période', `du ${day(invoice.periodStart)} au ${day(invoice.periodEnd)}`],
['Réglée le', day(paidAt)],
],
note: 'Rien à faire de votre côté : le prochain prélèvement aura lieu automatiquement le mois prochain.',
});
await this.mail
.sendWithAttachment(store.contactEmail, `Votre facture MonEspacePro ${invoice.number}`, text, `<p>${escapeHtml(text).replace(/\n/g, '<br>')}</p>`, {
.sendWithAttachment(store.contactEmail, `Votre facture MonEspacePro ${invoice.number}`, text, html, {
filename: `${invoice.number}.pdf`,
content: pdf,
})

View file

@ -4,7 +4,7 @@ import { Throttle } from '@nestjs/throttler';
import { Transform } from 'class-transformer';
import { Equals, IsEmail, IsIn, IsOptional, IsString, Length, MaxLength } from 'class-validator';
import { MailService } from '../mail/mail.service';
import { escapeHtml } from '../enrollment/pages';
import { emailLayout, esc } from '../mail/email-layout';
const trim = ({ value }: { value: unknown }) => (typeof value === 'string' ? value.trim() : value);
@ -73,7 +73,17 @@ export class ContactController {
['E-mail', dto.email],
];
const text = `${lines.map(([k, v]) => `${k} : ${v}`).join('\n')}\n\n${dto.message || '(pas de message)'}`;
const html = `<table>${lines.map(([k, v]) => `<tr><th align="left">${escapeHtml(k)}</th><td>${escapeHtml(v)}</td></tr>`).join('')}</table><p style="white-space:pre-wrap">${escapeHtml(dto.message || '(pas de message)')}</p>`;
const html = emailLayout({
webUrl: this.config.get('webUrl')!,
preheader: `${dto.firstName} ${dto.lastName} — ${dto.storeName}, ${dto.city}`,
eyebrow: 'Demande de démo',
title: `${dto.storeName} (${dto.city})`,
paragraphs: [
dto.message ? esc(dto.message).replace(/\n/g, '<br>') : '<em>Pas de message.</em>',
'Répondez directement à cet e-mail pour écrire au commerçant.',
],
details: lines.map(([k, v]) => [k, esc(v)] as [string, string]),
});
try {
await this.mail.send(to, `Demande de démo — ${dto.storeName} (${dto.city})`, text, html, dto.email);
} catch (e) {

View file

@ -4,7 +4,7 @@ import { randomBytes, timingSafeEqual } from 'crypto';
import { PrismaService } from '../prisma/prisma.service';
import { MailService } from '../mail/mail.service';
import { CARD_WITH_CONTEXT, CardWithContext } from '../wallet/wallet.types';
import { escapeHtml } from './pages';
import { emailLayout, esc } from '../mail/email-layout';
/** Alphabet sans caractères ambigus : le numéro peut être lu à voix haute au comptoir. */
const SERIAL_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
@ -115,7 +115,28 @@ export class EnrollmentService {
? `Bienvenue dans le programme ${program} de ${card.store.name} !`
: `Voici le lien de votre carte ${program}, comme demandé.`;
const text = `Bonjour ${card.customer.firstName},\n\n${intro}\n\nOuvrez ce lien sur votre téléphone pour ajouter la carte à Apple Wallet ou Google Wallet :\n${url}\n\nGardez cet e-mail : il vous permet de retrouver votre carte si vous changez de téléphone.\n\n${card.store.name}`;
const html = `<p>Bonjour ${escapeHtml(card.customer.firstName)},</p><p>${escapeHtml(intro)}</p><p><a href="${escapeHtml(url)}">Ajouter ma carte à mon téléphone</a></p><p>Gardez cet e-mail : il vous permet de retrouver votre carte si vous changez de téléphone.</p><p>${escapeHtml(card.store.name)}</p>`;
const unit = card.store.cardDesign?.pointsMode === 'STAMP' ? 'tampons' : 'points';
const reward = card.store.cardDesign?.rewards?.[0];
const html = emailLayout({
webUrl: this.config.get('webUrl')!,
preheader: isNew ? `Ajoutez votre carte ${program} à votre téléphone.` : `Le lien de votre carte ${program}.`,
eyebrow: card.store.name,
title: isNew ? `Votre carte est prête, ${card.customer.firstName} !` : 'Voici le lien de votre carte',
paragraphs: [
isNew
? `Bienvenue dans le programme <strong>${esc(program)}</strong> de ${esc(card.store.name)}.`
: `Comme demandé, voici le lien de votre carte <strong>${esc(program)}</strong>.`,
'Ouvrez ce lien <strong>sur votre téléphone</strong> pour ajouter la carte à Apple Wallet ou Google Wallet, puis présentez-la au comptoir à chaque passage.',
],
cta: { label: 'Ajouter ma carte à mon téléphone', url },
details: [
['Programme', esc(program)],
['Solde', `${card.balance} ${unit}`],
...(reward ? ([['Récompense', `${esc(reward.label)} à ${reward.cost} ${unit}`]] as [string, string][]) : []),
],
note: 'Gardez cet e-mail : il vous permet de retrouver votre carte si vous changez de téléphone.',
footnote: `Vous recevez cet e-mail car vous vous êtes inscrit au programme de fidélité de ${esc(card.store.name)}. Vous pouvez supprimer votre carte à tout moment depuis le lien ci-dessus.`,
});
await this.mail.send(card.customer.email, subject, text, html);
}
}

View file

@ -0,0 +1,145 @@
/**
* Gabarit des e-mails MonEspacePro, dans la charte du site vitrine
* (fond sable, carte blanche, titre fort, bouton vert, pied de page sombre).
*
* Contraintes des messageries : tableaux et styles en ligne uniquement
* (Outlook ignore flex/grid et la plupart des <style>), logo en PNG hébergé
* (pas de SVG), police Figtree en bonus avec repli Arial.
* Tout le texte passé ici doit déjà être échappé (utiliser `esc`).
*/
export const esc = (value: unknown) =>
String(value ?? '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
const C = {
bg: '#F6F6F3',
surface: '#FFFFFF',
ink: '#1C1C19',
muted: '#5A5A53',
border: '#E2E2DA',
green: '#0E7A66',
tint: '#E2EFEB',
yellow: '#F2B544',
footer: '#1C1C19',
footerMuted: '#9B9B90',
};
const FONT = "'Figtree', 'Segoe UI', Arial, Helvetica, sans-serif";
export interface EmailContent {
/** Adresse du site (logos et liens du pied de page). */
webUrl: string;
/** Texte d'aperçu affiché par la messagerie à côté du sujet. */
preheader: string;
/** Petit titre vert en capitales, au-dessus du titre. */
eyebrow?: string;
title: string;
/** Paragraphes (HTML déjà échappé, <strong> autorisé). */
paragraphs: string[];
cta?: { label: string; url: string };
/** Tableau clé / valeur (récapitulatif). */
details?: [string, string][];
/** Encadré vert pâle sous le bouton. */
note?: string;
/** Ligne d'information sous la carte (ex. « Envoyé par Boulangerie X via MonEspacePro »). */
footnote?: string;
}
export function emailLayout(m: EmailContent): string {
const p = (html: string) =>
`<p style="margin:0 0 16px;font-family:${FONT};font-size:17px;line-height:1.6;color:${C.ink};">${html}</p>`;
const cta = m.cta
? `<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin:8px 0 24px;">
<tr><td align="center" bgcolor="${C.green}" style="border-radius:12px;">
<a href="${esc(m.cta.url)}" target="_blank" style="display:inline-block;padding:16px 28px;font-family:${FONT};font-size:17px;font-weight:700;line-height:1.2;color:#FFFFFF;text-decoration:none;border-radius:12px;">${esc(m.cta.label)}</a>
</td></tr></table>
<p style="margin:0 0 24px;font-family:${FONT};font-size:13px;line-height:1.5;color:${C.muted};">Le bouton ne fonctionne pas ? Copiez ce lien dans votre navigateur :<br><a href="${esc(m.cta.url)}" style="color:${C.green};word-break:break-all;">${esc(m.cta.url)}</a></p>`
: '';
const details = m.details?.length
? `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:0 0 24px;border:1px solid ${C.border};border-radius:14px;border-collapse:separate;">
${m.details
.map(
([k, v], i) => `<tr>
<td style="padding:12px 16px;${i ? `border-top:1px solid ${C.border};` : ''}font-family:${FONT};font-size:14px;font-weight:600;color:${C.muted};width:38%;vertical-align:top;">${esc(k)}</td>
<td style="padding:12px 16px;${i ? `border-top:1px solid ${C.border};` : ''}font-family:${FONT};font-size:15px;color:${C.ink};vertical-align:top;">${v}</td>
</tr>`,
)
.join('')}
</table>`
: '';
const note = m.note
? `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:0 0 8px;">
<tr><td style="background:${C.tint};border-radius:14px;padding:16px 18px;font-family:${FONT};font-size:15px;line-height:1.5;color:${C.green};font-weight:600;">${m.note}</td></tr></table>`
: '';
return `<!doctype html>
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="x-apple-disable-message-reformatting">
<meta name="color-scheme" content="light">
<meta name="supported-color-schemes" content="light">
<title>${esc(m.title)}</title>
<link href="https://fonts.googleapis.com/css2?family=Figtree:wght@400;600;700;800&display=swap" rel="stylesheet">
<style>
@media (max-width: 620px) {
.mep-card { padding: 28px 22px !important; }
.mep-title { font-size: 26px !important; }
}
</style>
</head>
<body style="margin:0;padding:0;background:${C.bg};-webkit-text-size-adjust:100%;">
<div style="display:none;max-height:0;overflow:hidden;opacity:0;color:${C.bg};">${esc(m.preheader)}&#8199;&#65279;&#847;&#8199;&#65279;&#847;&#8199;&#65279;&#847;</div>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="${C.bg}" style="background:${C.bg};">
<tr><td align="center" style="padding:32px 16px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="max-width:600px;">
<!-- En-tête -->
<tr><td style="padding:0 4px 20px;">
<a href="${esc(m.webUrl)}" target="_blank" style="text-decoration:none;">
<img src="${esc(m.webUrl)}/assets/email-logo.png" width="36" height="36" alt="" style="display:inline-block;vertical-align:middle;border:0;">
<span style="display:inline-block;vertical-align:middle;margin-left:8px;font-family:${FONT};font-size:20px;font-weight:800;letter-spacing:-0.01em;color:${C.ink};">MonEspacePro</span>
</a>
</td></tr>
<!-- Carte -->
<tr><td class="mep-card" bgcolor="${C.surface}" style="background:${C.surface};border:1px solid ${C.border};border-radius:20px;padding:40px 40px 32px;">
${m.eyebrow ? `<p style="margin:0 0 12px;font-family:${FONT};font-size:13px;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;color:${C.green};">${esc(m.eyebrow)}</p>` : ''}
<h1 class="mep-title" style="margin:0 0 20px;font-family:${FONT};font-size:30px;line-height:1.15;font-weight:800;letter-spacing:-0.02em;color:${C.ink};">${esc(m.title)}</h1>
${m.paragraphs.map(p).join('\n')}
${cta}
${details}
${note}
</td></tr>
${m.footnote ? `<tr><td style="padding:16px 8px 0;font-family:${FONT};font-size:13px;line-height:1.5;color:${C.muted};text-align:center;">${m.footnote}</td></tr>` : ''}
<!-- Pied de page -->
<tr><td style="padding-top:24px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="${C.footer}" style="background:${C.footer};border-radius:20px;">
<tr><td style="padding:28px 32px;">
<img src="${esc(m.webUrl)}/assets/email-logo-clair.png" width="28" height="28" alt="" style="display:inline-block;vertical-align:middle;border:0;">
<span style="display:inline-block;vertical-align:middle;margin-left:8px;font-family:${FONT};font-size:17px;font-weight:800;color:#F3F3EC;">MonEspacePro</span>
<p style="margin:12px 0 16px;font-family:${FONT};font-size:14px;line-height:1.5;color:#B3B3A8;">La carte de fidélité dématérialisée pour les commerces indépendants.</p>
<p style="margin:0;font-family:${FONT};font-size:13px;line-height:1.6;color:${C.footerMuted};">
<a href="${esc(m.webUrl)}" style="color:#C9C9BF;text-decoration:underline;">monespacepro.eu</a> &nbsp;·&nbsp;
<a href="mailto:contact@monespacepro.eu" style="color:#C9C9BF;text-decoration:underline;">contact@monespacepro.eu</a> &nbsp;·&nbsp;
<a href="${esc(m.webUrl)}/confidentialite/" style="color:#C9C9BF;text-decoration:underline;">Confidentialité</a><br>
© MonEspacePro — EI Tony Averty
</p>
</td></tr></table>
</td></tr>
</table>
</td></tr></table>
</body>
</html>`;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
site/assets/email-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB