Skip to content

Commit

Permalink
Added more logging to EmailMessageRelay.cs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smightym8 committed Jul 10, 2024
1 parent af1c978 commit 4d47481
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ClubService.Infrastructure/Mail/EmailMessageRelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EmailMessageRelay : BackgroundService
{
private readonly ILoggerService<EmailMessageRelay> _loggerService;
private readonly int _pollingInterval;
private readonly MailAddress _senderEmailAddress;
private readonly string _senderEmailAddress;
private readonly IServiceProvider _serviceProvider;
private readonly SmtpClient _smtpClient;

Expand All @@ -24,7 +24,7 @@ public EmailMessageRelay(
_serviceProvider = serviceProvider;
_loggerService = loggerService;
_pollingInterval = smtpConfiguration.Value.PollingInterval;
_senderEmailAddress = new MailAddress(smtpConfiguration.Value.SenderEmailAddress);
_senderEmailAddress = smtpConfiguration.Value.SenderEmailAddress;
_smtpClient = new SmtpClient(smtpConfiguration.Value.Host, smtpConfiguration.Value.Port);
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
}
Expand All @@ -42,17 +42,28 @@ private async Task SendEmails()
await transactionManager.TransactionScope(async () =>
{
MailAddress recipientEmailAddress;
MailAddress senderMailAddress;
try
{
senderMailAddress = new MailAddress(_senderEmailAddress);
}
catch (FormatException)
{
_loggerService.LogInvalidEMailAddress(_senderEmailAddress);
throw;
}

try
{
recipientEmailAddress = new MailAddress(emailMessage.RecipientEMailAddress);
}
catch (FormatException e)
catch (FormatException)
{
_loggerService.LogInvalidEMailAddress(emailMessage.RecipientEMailAddress);
throw;
}

var mailMessage = new MailMessage(_senderEmailAddress, recipientEmailAddress)
var mailMessage = new MailMessage(senderMailAddress, recipientEmailAddress)
{
Subject = emailMessage.Subject,
Body = emailMessage.Body
Expand Down

0 comments on commit 4d47481

Please sign in to comment.