diff --git a/Messaging/TimedHostedService.cs b/Messaging/TimedHostedService.cs index 8f2d0e38..ec60fc77 100644 --- a/Messaging/TimedHostedService.cs +++ b/Messaging/TimedHostedService.cs @@ -47,14 +47,22 @@ private async Task DoWork(AppSettings appSettings, CancellationToken cls) .Options; using var dbContext = new MessagingContext(contextOptions); - // Check for emails - var emails = await EmailMessage.GetEmailsAsync(appSettings.ConnectionStrings.EmailUsername, appSettings.ConnectionStrings.EmailPassword, cls); - // Transform each email to a text message - foreach (var email in MemoryMarshal.ToEnumerable(emails)) + try { - await EmailToForwardedMessageAsync(email, dbContext); - _logger.LogInformation("[Background Worker] [EmailToText] Forwarded message To {to} From {from}", email.To, email.From); + // Check for emails + var emails = await EmailMessage.GetEmailsAsync(appSettings.ConnectionStrings.EmailUsername, appSettings.ConnectionStrings.EmailPassword, cls); + // Transform each email to a text message + foreach (var email in MemoryMarshal.ToEnumerable(emails)) + { + await EmailToForwardedMessageAsync(email, dbContext); + _logger.LogInformation("[Background Worker] [EmailToText] Forwarded message To {to} From {from}", email.To, email.From); + } } + catch (Exception ex) { + + _logger.LogInformation("[Background Worker] [EmailToText] Failed to get new email messages."); + } + // Send the messages outbound _logger.LogInformation("[Background Worker] Timed Hosted Service has completed."); }