Skip to content

Commit

Permalink
No need to new up a EmailClient instance on every email message (#16746)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Sep 18, 2024
1 parent c7b2e38 commit 86ec9fd
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public abstract class AzureEmailProviderBase : IEmailProvider
private readonly IEmailAddressValidator _emailAddressValidator;
private readonly ILogger _logger;

private EmailClient _emailClient;

protected readonly IStringLocalizer S;

public AzureEmailProviderBase(
Expand Down Expand Up @@ -132,8 +134,9 @@ public virtual async Task<EmailResult> SendAsync(MailMessage message)

try
{
var client = new EmailClient(_providerOptions.ConnectionString);
var emailResult = await client.SendAsync(WaitUntil.Completed, emailMessage);
_emailClient ??= new EmailClient(_providerOptions.ConnectionString);

var emailResult = await _emailClient.SendAsync(WaitUntil.Completed, emailMessage);

if (emailResult.HasValue)
{
Expand Down

0 comments on commit 86ec9fd

Please sign in to comment.