From e6ecbc2f78e67784adfea4d03a657502575b7b16 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sun, 27 Apr 2025 11:48:56 +0530 Subject: [PATCH] Fixed the bug of email template not found in production environment --- Marco.Pms.Services/Marco.Pms.Services.csproj | 5 +++++ Marco.Pms.Services/Service/EmailSender.cs | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Marco.Pms.Services/Marco.Pms.Services.csproj b/Marco.Pms.Services/Marco.Pms.Services.csproj index e65edaf..6482198 100644 --- a/Marco.Pms.Services/Marco.Pms.Services.csproj +++ b/Marco.Pms.Services/Marco.Pms.Services.csproj @@ -44,5 +44,10 @@ + + + PreserveNewest + + diff --git a/Marco.Pms.Services/Service/EmailSender.cs b/Marco.Pms.Services/Service/EmailSender.cs index 1baac55..59f5a11 100644 --- a/Marco.Pms.Services/Service/EmailSender.cs +++ b/Marco.Pms.Services/Service/EmailSender.cs @@ -10,16 +10,18 @@ namespace MarcoBMS.Services.Service { private readonly SmtpSettings _smtpSettings; private readonly IConfiguration _configuration; + private readonly IWebHostEnvironment _env; - public EmailSender(IOptions emailSettings, IConfiguration configuration) + public EmailSender(IOptions emailSettings, IConfiguration configuration, IWebHostEnvironment env) { _smtpSettings = emailSettings.Value; _configuration = configuration; + _env = env; } public async Task GetEmailTemplate(string templateName, Dictionary replacements) { - string path = Path.Combine(Directory.GetCurrentDirectory(), "EmailTemplates", $"{templateName}.html"); + string path = Path.Combine(_env.ContentRootPath, "EmailTemplates", $"{templateName}.html"); if (!File.Exists(path)) throw new FileNotFoundException("Template file not found"); @@ -52,7 +54,7 @@ namespace MarcoBMS.Services.Service await SendEmailAsync(toEmails, "New user registration, Reset Your Password", emailBody); } public async Task SendResetPasswordEmail(string toEmail, string userName, string resetLink) - { + { var replacements = new Dictionary { { "MAIL_TITLE", "Reset Your Password" }, -- 2.43.0