Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
PaymonK committed Apr 8, 2020
1 parent 3609d47 commit 19fd224
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Olive.Aws.Ses.AutoFetch/AwsSesEmailDispatcher.cs
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
}
}
}
};
}
}
}
13 changes: 13 additions & 0 deletions Olive.Aws.Ses.AutoFetch/IServiceCollectionExtension.cs
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>();
}
}
}
45 changes: 45 additions & 0 deletions Olive.Aws.Ses.AutoFetch/Olive.Aws.Ses.AutoFetch.csproj
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>
28 changes: 28 additions & 0 deletions Olive.Aws.Ses.AutoFetch/readme.txt
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();
6 changes: 6 additions & 0 deletions Olive.sln
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Olive.Entities.Data.Replica
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Olive.Console", "Olive.Console\Olive.Console.csproj", "{D9DCB1FC-5367-40EB-BD0C-0CE0AF14972F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Olive.Aws.Ses.AutoFetch", "Olive.Aws.Ses.AutoFetch\Olive.Aws.Ses.AutoFetch.csproj", "{E235C02C-0BAA-4E69-BAD2-3C7D7AE5BA2A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -389,6 +391,10 @@ Global
{D9DCB1FC-5367-40EB-BD0C-0CE0AF14972F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9DCB1FC-5367-40EB-BD0C-0CE0AF14972F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9DCB1FC-5367-40EB-BD0C-0CE0AF14972F}.Release|Any CPU.Build.0 = Release|Any CPU
{E235C02C-0BAA-4E69-BAD2-3C7D7AE5BA2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E235C02C-0BAA-4E69-BAD2-3C7D7AE5BA2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E235C02C-0BAA-4E69-BAD2-3C7D7AE5BA2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E235C02C-0BAA-4E69-BAD2-3C7D7AE5BA2A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 19fd224

Please sign in to comment.