-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Amazon.SimpleEmail; | ||
using Amazon.SimpleEmail.Model; | ||
using Olive.Email; | ||
using System; | ||
using System.Linq; | ||
using System.Net.Mail; | ||
using System.Threading.Tasks; | ||
|
||
namespace Olive.Aws.Ses | ||
{ | ||
public class AwsSesEmailDispatcher : IEmailDispatcher | ||
{ | ||
public async Task Dispatch(MailMessage mail, IEmailMessage _) | ||
{ | ||
var request = CreateEmailRequest(mail); | ||
|
||
using (var client = new AmazonSimpleEmailServiceClient()) | ||
{ | ||
var response = await client.SendEmailAsync(request); | ||
if (response.HttpStatusCode != System.Net.HttpStatusCode.OK) | ||
throw new Exception("Failed to send an email: " + response.HttpStatusCode); | ||
} | ||
} | ||
|
||
SendEmailRequest CreateEmailRequest(MailMessage mail) | ||
{ | ||
return new SendEmailRequest | ||
{ | ||
Source = mail.From.Address, | ||
Destination = new Destination | ||
{ | ||
ToAddresses = mail.To.Select(t => t.Address).ToList() | ||
}, | ||
Message = new Message | ||
{ | ||
Subject = new Content(mail.Subject), | ||
Body = new Body | ||
{ | ||
Html = new Content | ||
{ | ||
Charset = "UTF-8", | ||
Data = mail.Body | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Olive.Email; | ||
|
||
namespace Olive.Aws.Ses | ||
{ | ||
public static class IServiceCollectionExtension | ||
{ | ||
public static IServiceCollection AddAwsSesProvider(this IServiceCollection @this) | ||
{ | ||
return @this.AddTransient<IEmailDispatcher, AwsSesEmailDispatcher>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<PackageId>Olive.Aws.Ses.AutoFetch</PackageId> | ||
<PackageVersion>2.1.103</PackageVersion> | ||
<AssemblyVersion>2.1.0.0</AssemblyVersion> | ||
<FileVersion>2.1.0.0</FileVersion> | ||
<Title>Olive AWS SES Autofetch</Title> | ||
<Authors>Geeks Ltd</Authors> | ||
<PackageProjectUrl>https://github.com/Geeksltd/Olive</PackageProjectUrl> | ||
<PackageIconUrl>http://licensing.msharp.co.uk/Images/OliveComponent.png</PackageIconUrl> | ||
<Copyright>Copyright ©2020 Geeks Ltd - All rights reserved.</Copyright> | ||
<Description>A plugin for Olive Framework</Description> | ||
<OutputPath>..\bin</OutputPath> | ||
<DocumentationFile>..\bin\netcoreapp2.1\Olive.Aws.Ses.xml</DocumentationFile> | ||
<NoWarn>1701;1702;1705;1591;1573;NU1701</NoWarn> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.3.6.20" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.1.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="readme.txt" pack="true" PackagePath="." /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="Olive"> | ||
<HintPath>..\bin\netstandard2.0\Olive.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Olive.Entities"> | ||
<HintPath>..\bin\netstandard2.0\Olive.Entities.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Olive.Aws"> | ||
<HintPath>..\bin\netstandard2.0\Olive.Aws.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Olive.Email"> | ||
<HintPath>..\bin\netcoreapp2.1\Olive.Email.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> | ||
<Exec Command="update-local-nuget-cache $(ProjectPath) $(TargetPath) $(TargetName)" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
In Startup.cs, kick start the fetching engine. | ||
|
||
using Olive.Aws.Ses.AutoFetch; | ||
|
||
public override void Configure(IApplicationBuilder app) | ||
{ | ||
.... | ||
// Option 1: Use the built-in default type of AutoFetch.MailMessage. | ||
new Mailbox().Watch("[email protected]"); | ||
|
||
// Option 2: Use your own type, which should implement AutoFetch.IMailMessage. | ||
new Mailbox().Watch<MyOwnMessageType>("[email protected]"); | ||
} | ||
|
||
|
||
NOTE | ||
================================================== | ||
If Option 1 is used, upon application startup, the following database table will | ||
be automatically created for store records of AutoFetch.MailMessage class. | ||
|
||
CREATE TABLE [MailMessage] | ||
... | ||
|
||
|
||
EXECUTION | ||
================================================== | ||
Create a background process to call the following: | ||
await new Mailbox().FetchAll(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters