using System; namespace ManagerService.EmailTemplates { /// /// Shared HTML shell for all transactional emails. Palette taken from the /// MyInfoMate platform deck: navy #0a1222, cyan #0df2df, teal #0e8f8a. /// public static class EmailLayout { /// Absolute URL of the logo shown in the header band. Empty = wordmark only. public static string LogoUrl { get; private set; } = ""; /// Public site linked from the footer. Empty = no link. public static string LandingUrl { get; private set; } = ""; /// Called once at startup from configuration (see Startup.cs). public static void Configure(string logoUrl, string landingUrl) { // Une URL relative afficherait une image cassée dans la boîte de // réception : mieux vaut le bandeau sans logo que ça. LogoUrl = logoUrl != null && logoUrl.StartsWith("http") ? logoUrl : ""; LandingUrl = landingUrl ?? ""; } public static string Render(string title, string bodyHtml, string ctaText = null, string ctaUrl = null) { var hasCta = !string.IsNullOrEmpty(ctaText) && !string.IsNullOrEmpty(ctaUrl); // Le texte de pré-en-tête est ce que la boîte de réception affiche à // côté de l'objet : sans lui elle recopie le début du HTML. var preheader = StripTags(bodyHtml); if (preheader.Length > 140) preheader = preheader.Substring(0, 140) + "…"; var logoHtml = string.IsNullOrEmpty(LogoUrl) ? "" : $@""; var ctaHtml = ""; if (hasCta) { ctaHtml = $@"
{ctaText}

Le bouton ne fonctionne pas ? Copiez ce lien dans votre navigateur :
{ctaUrl}

"; } var landingHtml = string.IsNullOrEmpty(LandingUrl) ? "" : $@" · myinfomate.be"; return $@" {title}
{preheader}
{logoHtml} MyInfoMate
 

{title}

{bodyHtml}
{ctaHtml}
MyInfoMate — la plateforme de contenu des lieux culturels.
© {DateTime.UtcNow.Year} Unov{landingHtml}
"; } private static string StripTags(string html) { if (string.IsNullOrEmpty(html)) return ""; var sb = new System.Text.StringBuilder(html.Length); var inTag = false; foreach (var c in html) { if (c == '<') inTag = true; else if (c == '>') inTag = false; else if (!inTag) sb.Append(c); } return sb.ToString().Replace(" ", " ").Trim(); } } }