finalizare 1.0
This commit is contained in:
@@ -1,26 +1,19 @@
|
||||
using Application.Services.Email;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using Application.Services.Email;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Infrastructure.Services.Email;
|
||||
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
public class EmailService : IEmailService
|
||||
public class EmailService(IOptions<SmtpSettings> smtpSettings) : IEmailService
|
||||
{
|
||||
private readonly SmtpSettings _smtpSettings;
|
||||
|
||||
public EmailService(IOptions<SmtpSettings> smtpSettings)
|
||||
{
|
||||
_smtpSettings = smtpSettings.Value;
|
||||
}
|
||||
private readonly 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.EnableSsl = _smtpSettings.EnableSsl;
|
||||
client.Credentials = new NetworkCredential(_smtpSettings.UserName, _smtpSettings.Password);
|
||||
|
||||
var mailMessage = new MailMessage
|
||||
@@ -36,7 +29,7 @@ public class EmailService : IEmailService
|
||||
}
|
||||
}
|
||||
|
||||
public string GenerateCredentialsEmailBody(string email, string password)
|
||||
public string GenerateCredentialsEmailBody(string name, string email, string password)
|
||||
{
|
||||
var template = @"
|
||||
<html>
|
||||
@@ -49,21 +42,32 @@ public class EmailService : IEmailService
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
return template.Replace("{email}", email).Replace("{password}", password);
|
||||
return template.Replace("{name}", name).Replace("{email}", email).Replace("{password}", password);
|
||||
}
|
||||
|
||||
public string GenerateResetCredentialsEmailBody(string email, string password)
|
||||
public string GenerateResetCredentialsEmailBody(string name, string email, string password)
|
||||
{
|
||||
var template = @"
|
||||
<html>
|
||||
<body>
|
||||
<h1>Password Reset Successful</h1>
|
||||
<p>Hello {name},
|
||||
<p>Your password has been successfully reset. You can now log in to your HealthcareManager account using your new password.</p>
|
||||
<p>If you did not request a password reset, please contact our support team immediately.</p>
|
||||
<p>For security reasons, it's recommended to keep your password confidential and to change it regularly.</p>
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
return template.Replace("{email}", email).Replace("{password}", password);
|
||||
return template.Replace("{name}", name).Replace("{email}", email).Replace("{password}", password);
|
||||
}
|
||||
|
||||
public string GetSuccessfulRegistrationSubject()
|
||||
{
|
||||
return "Welcome to HealthcareManager!";
|
||||
}
|
||||
|
||||
public string GetSuccessfulPasswordResetSubject()
|
||||
{
|
||||
return "Password reset successfully!";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user