Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new abstractions package #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Skyhop.Mail.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Templates", "samples
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skyhop.Mail", "src\Skyhop.Mail\Skyhop.Mail.csproj", "{23BAD21E-79CB-4665-AD95-EDC0B2449C58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skyhop.Mail.Abstractions", "src\Skyhop.Mail.Abstractions\Skyhop.Mail.Abstractions.csproj", "{1F4A7C5A-53F6-441B-ADAC-E880AB4CA3B6}"
corstian marked this conversation as resolved.
Show resolved Hide resolved
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -56,6 +58,10 @@ Global
{23BAD21E-79CB-4665-AD95-EDC0B2449C58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23BAD21E-79CB-4665-AD95-EDC0B2449C58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23BAD21E-79CB-4665-AD95-EDC0B2449C58}.Release|Any CPU.Build.0 = Release|Any CPU
{1F4A7C5A-53F6-441B-ADAC-E880AB4CA3B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F4A7C5A-53F6-441B-ADAC-E880AB4CA3B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F4A7C5A-53F6-441B-ADAC-E880AB4CA3B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F4A7C5A-53F6-441B-ADAC-E880AB4CA3B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -67,6 +73,7 @@ Global
{B20B9859-B36F-4C12-8AEE-2E4631E6E477} = {421325E9-9344-43DD-962E-D1FE890F7E8D}
{EDF5D8A1-8DBA-43C6-BD58-4A2933E8A985} = {421325E9-9344-43DD-962E-D1FE890F7E8D}
{23BAD21E-79CB-4665-AD95-EDC0B2449C58} = {B03343F8-EE4C-4386-90BF-94225E44D24C}
{1F4A7C5A-53F6-441B-ADAC-E880AB4CA3B6} = {B03343F8-EE4C-4386-90BF-94225E44D24C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {02451752-289A-4A52-9BBF-1BCB4C640289}
Expand Down
40 changes: 40 additions & 0 deletions src/Skyhop.Mail.Abstractions/IMailDispatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using MimeKit;
using System;
using System.Threading.Tasks;

namespace Skyhop.Mail.Abstractions
{
/// <summary>
/// Interface to a class used to generate and send emails
/// </summary>
public interface IMailDispatcher
{
/// <summary>
/// Sends the email
/// </summary>
/// <typeparam name="T">The type of the model carrying the payload of the mail.</typeparam>
/// <param name="data">The message payload</param>
/// <param name="to">The addresses to which the mail must be sent</param>
/// <param name="cc">The addresses to which the mail must be cc'ed.</param>
/// <param name="bcc">The addresses to which the mail must be bcc'ed.</param>
/// <param name="from">The addresses from which the mail is sent, can be null.</param>
/// <returns>An awaitable <seealso cref="Task"/> which represents this method call.</returns>
public Task SendMail<T>(
T data,
MailboxAddress[] to,
MailboxAddress[]? cc = default,
MailboxAddress[]? bcc = default,
MailboxAddress? from = default) where T : MailBase;

/// <summary>
/// Sends the email
/// </summary>
/// <typeparam name="T">The type of the model carrying the payload of the mail.</typeparam>
/// <param name="data">The message payload</param>
/// <param name="senderTransformation">An async action that can be used to set the different properties on the <seealso cref="IMessageSenderInfo"/>. The To and From properties must be set.</param>
/// <returns>An awaitable <seealso cref="Task"/> which represents this method call.</returns>
public Task SendMail<T>(
corstian marked this conversation as resolved.
Show resolved Hide resolved
T data,
Func<IMessageSenderInfo, Task> senderTransformation) where T : MailBase;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Skyhop.Mail
{
/// <summary>
/// Base class for all view-models for the <seealso cref="MailDispatcher"/> views
/// Base class for all view-models for the <seealso cref="IMailDispatcher"/> views
/// </summary>
public class MailBase
{
Expand Down Expand Up @@ -61,7 +61,7 @@ public AttachmentCollection LinkedResources
/// <summary>
/// The body builder used for the <see cref="Attachments"/>, <see cref="LinkedResources"/>, Html body and text body of the message.
/// </summary>
protected internal BodyBuilder BodyBuilder { get; }
public BodyBuilder BodyBuilder { get; }

/// <summary>
/// A transform that can be used to update message headers and/or content before sending the message.
Expand Down
27 changes: 27 additions & 0 deletions src/Skyhop.Mail.Abstractions/PackageDetails.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup>
<PackageVersion>3.0.0-rc5</PackageVersion>
<VersionPrefix>0.0.1</VersionPrefix>
<VersionPrefix Condition="'$(packageversion)' != ''">$(PackageVersion)</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageTags>mail razor</PackageTags>
<Title>Skyhop.Mail.Abstractions</Title>
<Product>$(Title)</Product>
<Description>A library smoothing email generation from .NET code, by enforcing a strong boundary between the template, and code rendering the template.</Description>
<PackageProjectUrl>https://github.com/skyhop/Mail</PackageProjectUrl>
<RepositoryUrl>https://github.com/skyhop/Mail</RepositoryUrl>
<PackageReleaseNotes>
- Split the interfaces and base classes into different packages
</PackageReleaseNotes>
</PropertyGroup>

</Project>
13 changes: 13 additions & 0 deletions src/Skyhop.Mail.Abstractions/Skyhop.Mail.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$(MSBuildThisFileDirectory)\PackageDetails.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
corstian marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MimeKit" Version="2.10.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Skyhop.Mail/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IServiceCollection AddMailDispatcher(this IServiceCollection servi
// Renderer + internal dependencies
serviceCollection.AddSingleton<RazorViewToStringRenderer>();
serviceCollection.AddSingleton<IModelIdentifierLister, ModelIdentifierLister>();
serviceCollection.AddSingleton<MailDispatcher>();
serviceCollection.AddSingleton<IMailDispatcher, MailDispatcher>();
serviceCollection.Configure(mailDispatcherOptionsBuilder ?? (_ => { } ));

// Try add if not already added needed Razor dependencies
Expand Down
2 changes: 1 addition & 1 deletion src/Skyhop.Mail/MailDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Skyhop.Mail
/// <summary>
/// Class used to generate and send emails
/// </summary>
public class MailDispatcher
public class MailDispatcher : IMailDispatcher
{
corstian marked this conversation as resolved.
Show resolved Hide resolved
private readonly RazorViewToStringRenderer _renderer;
private readonly MailDispatcherOptions _options;
Expand Down
4 changes: 2 additions & 2 deletions src/Skyhop.Mail/PackageDetails.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<PackageVersion>3.0.0-rc4</PackageVersion>
<PackageVersion>3.0.0-rc5</PackageVersion>
<VersionPrefix>0.0.1</VersionPrefix>
<VersionPrefix Condition="'$(packageversion)' != ''">$(PackageVersion)</VersionPrefix>
<VersionSuffix></VersionSuffix>
Expand All @@ -20,7 +20,7 @@
<PackageProjectUrl>https://github.com/skyhop/Mail</PackageProjectUrl>
<RepositoryUrl>https://github.com/skyhop/Mail</RepositoryUrl>
<PackageReleaseNotes>
- Added transformations to edit the message content and senderinfo
- Split the interfaces and base classes into different packages
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/Skyhop.Mail/Skyhop.Mail.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.0" />
<PackageReference Include="PreMailer.Net" Version="2.1.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Skyhop.Mail.Abstractions\Skyhop.Mail.Abstractions.csproj" />
</ItemGroup>

</Project>