using Application.Services.Email; namespace Infrastructure.Services.Email; using System.Net; using System.Net.Mail; using System.Threading.Tasks; using Microsoft.Extensions.Options; public class EmailService : IEmailService { private readonly SmtpSettings _smtpSettings; public EmailService(IOptions smtpSettings) { _smtpSettings = smtpSettings.Value; } public async Task SendEmailAsync(string to, string subject, string body) { using (var client = new SmtpClient(_smtpSettings.Host, _smtpSettings.Port)) { client.EnableSsl = _smtpSettings.EnableSSL; client.Credentials = new NetworkCredential(_smtpSettings.UserName, _smtpSettings.Password); var mailMessage = new MailMessage { From = new MailAddress(_smtpSettings.From), Subject = subject, Body = body, IsBodyHtml = true }; mailMessage.To.Add(to); await client.SendMailAsync(mailMessage); } } public string GenerateCredentialsEmailBody(string email, string password) { var template = @"

Welcome to HealthcareManager

You can now log in using the following credentials:

Email: {email}

Password: {password}

Thank you for choosing our services and we wish you an amazing day!

"; return template.Replace("{email}", email).Replace("{password}", password); } public string GenerateResetCredentialsEmailBody(string email, string password) { var template = @"

Password Reset Successful

Your password has been successfully reset. You can now log in to your HealthcareManager account using your new password.

If you did not request a password reset, please contact our support team immediately.

For security reasons, it's recommended to keep your password confidential and to change it regularly.

"; return template.Replace("{email}", email).Replace("{password}", password); } }