Skip to content

Commit

Permalink
Added a try catch for when the email server breaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Nov 16, 2024
1 parent 1e717bc commit 5a02118
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Messaging/TimedHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 61 in Messaging/TimedHostedService.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The variable 'ex' is declared but never used

Check warning on line 61 in Messaging/TimedHostedService.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The variable 'ex' is declared but never used

Check warning on line 61 in Messaging/TimedHostedService.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used

Check warning on line 61 in Messaging/TimedHostedService.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used

Check warning on line 61 in Messaging/TimedHostedService.cs

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

The variable 'ex' is declared but never used

Check warning on line 61 in Messaging/TimedHostedService.cs

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

The variable 'ex' is declared but never used

_logger.LogInformation("[Background Worker] [EmailToText] Failed to get new email messages.");
}

// Send the messages outbound
_logger.LogInformation("[Background Worker] Timed Hosted Service has completed.");
}
Expand Down

0 comments on commit 5a02118

Please sign in to comment.