Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions Skyhop.Mail.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B03343F8-EE4
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
src\PackageDetails.props = src\PackageDetails.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{923EB0D6-45A2-4E56-9979-E80FAF9EDE75}"
Expand All @@ -38,6 +39,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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skyhop.Mail.Abstractions", "src\Skyhop.Mail.Abstractions\Skyhop.Mail.Abstractions.csproj", "{1F4A7C5A-53F6-441B-ADAC-E880AB4CA3B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -56,6 +59,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 +74,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
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
25 changes: 25 additions & 0 deletions src/PackageDetails.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

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

<PropertyGroup>
<PackageVersion>3.0.0-rc6</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>
<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>
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>(
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
12 changes: 12 additions & 0 deletions src/Skyhop.Mail.Abstractions/PackageDetails.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<PropertyGroup>
<Title>Skyhop.Mail.Abstractions</Title>
<Product>$(Title)</Product>
<PackageReleaseNotes>
- Split the interfaces and base classes into different packages
</PackageReleaseNotes>
</PropertyGroup>

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

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

<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
25 changes: 4 additions & 21 deletions src/Skyhop.Mail/MailDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

namespace Skyhop.Mail
{
/// <summary>
/// Class used to generate and send emails
/// </summary>
public class MailDispatcher
/// <inheritdoc/>
public class MailDispatcher : IMailDispatcher
{
private readonly RazorViewToStringRenderer _renderer;
private readonly MailDispatcherOptions _options;
Expand All @@ -33,16 +31,7 @@ public MailDispatcher(RazorViewToStringRenderer renderer, IOptions<MailDispatche
_scopeFactory = scopeFactory;
}

/// <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, but then a DefaultFromAddress in <seealso cref="MailDispatcherOptions"/> must be set.</param>
/// <returns>An awaitable <seealso cref="Task"/> which represents this method call.</returns>
/// <inheritdoc />
public Task SendMail<T>(
T data,
MailboxAddress[] to,
Expand All @@ -69,13 +58,7 @@ public Task SendMail<T>(
return SendMail(data, senderTransform);
}

/// <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>
/// <inheritdoc />
public async Task SendMail<T>(T data, Func<IMessageSenderInfo, Task> senderTransformation)
where T : MailBase
{
Expand Down
18 changes: 1 addition & 17 deletions src/Skyhop.Mail/PackageDetails.props
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

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

<PropertyGroup>
<PackageVersion>3.0.0-rc4</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</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>
- Added transformations to edit the message content and senderinfo
- Split the interfaces and base classes into different packages
</PackageReleaseNotes>
</PropertyGroup>

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

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

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.17" />
<PackageReference Include="MailKit" Version="2.4.1" />
<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>