Skip to content

Commit

Permalink
SES V2
Browse files Browse the repository at this point in the history
  • Loading branch information
coronabytes committed Jan 21, 2024
1 parent 017faf6 commit b0a64cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Core.Email.Provider.SES/Core.Email.Provider.SES.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.SimpleEmailV2" Version="3.7.300.39" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.300.37" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
Expand Down
29 changes: 22 additions & 7 deletions Core.Email.Provider.SES/SimpleEmailServiceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Amazon;
using Amazon.SimpleEmail;
using Amazon.SimpleEmail.Model;
using Amazon.SimpleEmailV2;
using Amazon.SimpleEmailV2.Model;
using Core.Email.Abstractions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -13,12 +13,12 @@ internal class SimpleEmailServiceProvider : ICoreEmailProvider
{
private readonly Options _options = new();

private readonly AmazonSimpleEmailServiceClient _ses;
private readonly AmazonSimpleEmailServiceV2Client _ses;

public SimpleEmailServiceProvider(IConfiguration configuration, [ServiceKey] string key)
{
configuration.Bind($"Email:{key}", _options);
_ses = new AmazonSimpleEmailServiceClient(_options.AccessKey, _options.SecretAccessKey,
_ses = new AmazonSimpleEmailServiceV2Client(_options.AccessKey, _options.SecretAccessKey,
RegionEndpoint.GetBySystemName(_options.Region ?? "eu-central-1"));
}

Expand Down Expand Up @@ -67,9 +67,24 @@ public async Task<List<CoreEmailStatus>> SendBatchAsync(List<CoreEmailMessage> m
await m.WriteToAsync(stream, cancellationToken);
stream.Position = 0;

var res = await _ses
.SendRawEmailAsync(new SendRawEmailRequest(new RawMessage(stream)), cancellationToken)
.ConfigureAwait(false);
var res = await _ses.SendEmailAsync(new SendEmailRequest
{
FromEmailAddress = message.From,
Destination = new Destination
{
ToAddresses = message.To,
CcAddresses = message.Cc,
BccAddresses = message.Bcc
},
Content = new EmailContent
{
Raw = new RawMessage
{
Data = stream
}
},
ReplyToAddresses = string.IsNullOrEmpty(message.ReplyTo) ? new () : [message.ReplyTo]
}, cancellationToken).ConfigureAwait(false);

list.Add(new CoreEmailStatus
{
Expand Down

0 comments on commit b0a64cc

Please sign in to comment.