using System; using System.IO; using Microsoft.AspNetCore.Hosting; using Serilog; namespace Landmark.OLA.Application.Services.Email { public class EmailTemplateService : IEmailTemplateService { private readonly string _embeddedLogoBase64; public EmailTemplateService(IWebHostEnvironment webHostEnvironment) { _embeddedLogoBase64 = LoadEmbeddedLogo(webHostEnvironment); } private static string LoadEmbeddedLogo(IWebHostEnvironment webHostEnvironment) { if (webHostEnvironment == null) { return string.Empty; } try { var logoPath = Path.Combine(webHostEnvironment.ContentRootPath, "Files", "Logo.png"); if (!File.Exists(logoPath)) { Log.Warning("Logo not found at {LogoPath}. Email will fall back to remote image.", logoPath); return string.Empty; } var bytes = File.ReadAllBytes(logoPath); return Convert.ToBase64String(bytes); } catch (Exception ex) { Log.Warning(ex, "Failed to embed logo from file."); return string.Empty; } } public string BuildBrandedBody(string contentHtml, string redBannerMessage = "") { var topLogoTag = $""; var bottomLogoTag = $"\"Landmark"; redBannerMessage ??= string.Empty; var bannerHtml = string.IsNullOrWhiteSpace(redBannerMessage) ? string.Empty : "
" + "" + redBannerMessage + "

" + "
"; var requestBody = "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + topLogoTag + "
" + "" + "" + "" + "" + "" + "" + "" + "
" + bannerHtml + contentHtml + "
" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
 
 " + "
" + "
" + bottomLogoTag + "
" + "
" + "
" + " 
 
" + "" + ""; return requestBody; } } }