Skip to content

Commit

Permalink
#72 added SocketException reconnect retry
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Aug 10, 2024
1 parent 087f638 commit e881f9b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 64 deletions.
13 changes: 6 additions & 7 deletions samples/WorkerServiceExample/EmailWorkerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace MailKitSimplified.Sender.Models
namespace ExampleNamespace;

public class EmailWorkerOptions
{
public class EmailWorkerOptions
{
public const string SectionName = "EmailWorker";
public const string SectionName = "EmailWorker";

public string DefaultFromAddress { get; set; } = "noreply@localhost";
public string DefaultToAddress { get; set; } = "noreply@localhost";
}
public string DefaultFromAddress { get; set; } = "noreply@localhost";
public string DefaultToAddress { get; set; } = "noreply@localhost";
}
6 changes: 3 additions & 3 deletions samples/WorkerServiceExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using MailKitSimplified.Sender;
using MailKitSimplified.Receiver;
using MailKitSimplified.Sender.Models;
using ExampleNamespace;

IHost host = Host.CreateDefaultBuilder(args)
using var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddHostedService<ExampleNamespace.Worker>();
services.AddHostedService<Worker>();
//services.AddMailKitSimplifiedEmail(context.Configuration);
services.AddScopedMailKitSimplifiedEmailSender(context.Configuration);
services.AddScopedMailKitSimplifiedEmailReceiver(context.Configuration);
Expand Down
10 changes: 4 additions & 6 deletions samples/WorkerServiceExample/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using MailKitSimplified.Receiver.Extensions;
using MailKitSimplified.Receiver.Services;
using MailKitSimplified.Sender.Abstractions;
using MailKitSimplified.Sender.Models;
using Microsoft.Extensions.Options;

namespace ExampleNamespace;
Expand Down Expand Up @@ -48,9 +47,9 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken =
//await AddFlagsToNewestMessageSummaryAsync(cancellationToken);
//await GetMailFolderCacheAsync();
//await CreateFolderAndMoveTopOneAsync();
//await MonitorAsync(cancellationToken);
await MonitorAsync(cancellationToken);
//await MoveToAsync(_processed, 1, cancellationToken);
await MonitorMoveAsync(cancellationToken);
//await MonitorMoveAsync(cancellationToken);
}

private static ImapReceiver CreateExchangeOAuth2ImapClientExample(SaslMechanismOAuth2 oauth2)
Expand Down Expand Up @@ -494,17 +493,16 @@ async Task ProcessMessageAsync(IMessageSummary messageSummary)
private async Task MonitorAsync(CancellationToken cancellationToken = default)
{
using var smtpSender = _serviceScope.ServiceProvider.GetRequiredService<ISmtpSender>();
var sendTask = DelayedSendAsync(TimeSpan.FromMilliseconds(500), smtpSender, cancellationToken);
void ProcessMessage(IMessageSummary messageSummary) =>
_logger.LogInformation($"{_imapReceiver} message #{messageSummary.UniqueId} processed.");
var sendTask = DelayedSendAsync(TimeSpan.FromSeconds(3), smtpSender, cancellationToken);
await _imapReceiver.MonitorFolder
.SetMessageSummaryItems()
.SetIgnoreExistingMailOnConnect()
.SetIgnoreExistingMailOnConnect()
.OnMessageArrival(ProcessMessage)
.OnMessageDeparture(ProcessMessage)
.IdleAsync(cancellationToken);
await sendTask;
_logger.LogInformation($"{_imapReceiver} Monitoring complete.");
}

public override void Dispose()
Expand Down
Loading

0 comments on commit e881f9b

Please sign in to comment.