From 8a671b0176f2f7efc81efe672294c6e7c36f50e3 Mon Sep 17 00:00:00 2001 From: Morgana Date: Wed, 1 Apr 2026 19:30:09 +0000 Subject: [PATCH] fix: implement SendWelcomeEmailToUserAsync in ResendEmailService --- .../Services/ResendEmailService.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/ClientManager.Infrastructure/Services/ResendEmailService.cs b/src/ClientManager.Infrastructure/Services/ResendEmailService.cs index 6e66ef4..1130cfe 100644 --- a/src/ClientManager.Infrastructure/Services/ResendEmailService.cs +++ b/src/ClientManager.Infrastructure/Services/ResendEmailService.cs @@ -71,4 +71,68 @@ public async Task SendWelcomeEmailAsync(string email, string name, byte[]? attac logger.LogError(ex, "Exception while sending email to {Email} via Resend", email); } } + + public async Task SendWelcomeEmailToUserAsync(string email, string username) + { + var apiKey = configuration["Resend:ApiKey"]; + var fromEmail = configuration["Resend:FromEmail"] ?? "onboarding@resend.dev"; + var fromName = configuration["Resend:FromName"] ?? "ClientManager"; + + if (string.IsNullOrEmpty(apiKey)) + { + logger.LogWarning("Resend API key not configured. Skipping welcome email to {Email}", email); + return; + } + + try + { + using var client = new SmtpClient("smtp.resend.com", 465) + { + Credentials = new NetworkCredential("resend", apiKey), + EnableSsl = true + }; + + var htmlContent = $@" +
+
+

Welcome to ClientManager!

+
+
+

Hello {username},

+

Congratulations! Your registration at ClientManager has been completed successfully.

+

You now have full access to our client and document management platform.

+
+

Next steps:

+
    +
  • Access your account and complete your profile
  • +
  • Start registering your clients
  • +
  • Upload and organize your documents
  • +
  • Explore all available features
  • +
+
+

If you have any questions, our team is ready to help.

+

Best regards,
ClientManager Team

+
+
+

© {DateTime.UtcNow.Year} ClientManager. All rights reserved.

+
+
"; + + var mailMessage = new MailMessage + { + From = new MailAddress(fromEmail, fromName), + Subject = "Welcome to ClientManager!", + Body = htmlContent, + IsBodyHtml = true + }; + mailMessage.To.Add(new MailAddress(email, username)); + + await client.SendMailAsync(mailMessage); + logger.LogInformation("Welcome email sent successfully to {Email} via Resend", email); + } + catch (Exception ex) + { + logger.LogError(ex, "Exception while sending welcome email to {Email} via Resend", email); + } + } }