Skip to content

Commit

Permalink
Updated readme and packages descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco committed Jul 8, 2023
1 parent 4160192 commit 6d76d11
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 31 deletions.
139 changes: 139 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,142 @@ This library is based on the excellent [FluentEmail](https://github.com/lukencod

> Note: This library is not compatible with .NET Framework projects.

[![NuGet](https://img.shields.io/nuget/v/FluentEmailer.Core.svg)](https://nuget.org/packages/FluentEmailer.Core)
[![MIT](https://img.shields.io/github/license/marcoatribeiro/FluentEmailer)](https://github.com/marcoatribeiro/FluentEmailer/LICENSE)

## Nuget Packages

### Core Library

* [FluentEmailer.Core](src/FluentEmailer.Core) - Just the domain model. Includes very basic defaults, but is also included with every other package here.
* [FluentEmailer.Smtp](src/Senders/FluentEmailer.Smtp) - Send email via SMTP server.

### Renderers

* [FluentEmailer.Liquid](src/Renderers/FluentEmailer.Liquid) - Generate emails using [Liquid templates](https://shopify.github.io/liquid/). Uses the [Fluid](https://github.com/sebastienros/fluid) project under the hood.

### Mail Provider Integrations

* [FluentEmailer.MailerSend](src/Senders/FluentEmailer.MailerSend) - Send email via [MailerSend](https://www.mailersend.com/)'s REST API.


## Basic Usage
```csharp
var email = await Email
.From("[email protected]")
.To("[email protected]", "bob")
.Subject("hows it going bob")
.Body("yo bob, long time no see!")
.SendAsync();
```


## Dependency Injection

Configure FluentEmailer in startup.cs with these helper methods. This will inject `IFluentEmailer` (send a single email) and `IFluentEmailerFactory` (used to send multiple emails in a single context) with the
ISender and ITemplateRenderer configured using AddLiquidRenderer(), AddSmtpSender() or other packages.

```csharp
public void ConfigureServices(IServiceCollection services)
{
services
.AddFluentEmail("[email protected]")
.AddLiquidRenderer()
.AddSmtpSender("localhost", 25);
}
```
Example to take a dependency on IFluentEmailer:

```c#
public class EmailService {

private IFluentEmailer _fluentEmailer;

public EmailService(IFluentEmailer fluentEmailer) {
_fluentEmailer = fluentEmailer;
}

public async Task Send() {
await _fluentEmailer.To("[email protected]")
.Body("The body").SendAsync();
}
}
```


## Using a Liquid template

[Liquid templates](https://shopify.github.io/liquid/) are a more secure option for Razor templates as they run in more restricted environment.
While Razor templates have access to whole power of CLR functionality like file access, they also
are more insecure if templates come from untrusted source. Liquid templates also have the benefit of being faster
to parse initially as they don't need heavy compilation step like Razor templates do.

Model properties are exposed directly as properties in Liquid templates so they also become more compact.

See [Fluid samples](https://github.com/sebastienros/fluid) for more examples.

```csharp
// Using Liquid templating package (or set using AddLiquidRenderer in services)
// file provider is used to resolve layout files if they are in use
var fileProvider = new PhysicalFileProvider(Path.Combine(someRootPath, "EmailTemplates"));
var options = new LiquidRendererOptions
{
FileProvider = fileProvider
};

Email.DefaultRenderer = new LiquidRenderer(Options.Create(options));

// template which utilizes layout
var template = @"
{% layout '_layout.liquid' %}
Dear {{ Name }}, You are totally {{ Compliment }}.";

var email = Email
.From("[email protected]")
.To("[email protected]")
.Subject("woo nuget")
.UsingTemplate(template, new ViewModel { Name = "Luke", Compliment = "Awesome" });
```

## Sending Emails

```csharp
// Using Smtp Sender package (or set using AddSmtpSender in services)
Email.DefaultSender = new SmtpSender();

//send normally
email.Send();

//send asynchronously
await email.SendAsync();
```

## Template File from Disk

```csharp
var email = Email
.From("[email protected]")
.To("[email protected]")
.Subject("woo nuget")
.UsingTemplateFromFile($"{Directory.GetCurrentDirectory()}/Mytemplate.cshtml", new { Name = "Rad Dude" });
```

## Embedded Template File

**Note for .NET Core 2 users:** You'll need to add the following line to the project containing any embedded razor views. See [this issue for more details](https://github.com/aspnet/Mvc/issues/6021).

```xml
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
```

```csharp
var email = new Email("[email protected]")
.To("[email protected]")
.Subject("Hey cool name!")
.UsingTemplateFromEmbedded("Example.Project.Namespace.template-name.cshtml",
new { Name = "Bob" },
TypeFromYourEmbeddedAssembly.GetType().GetTypeInfo().Assembly);
```

2 changes: 1 addition & 1 deletion Src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RepositoryUrl>https://github.com/marcoatribeiro/FluentEmailer</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>fluentemailer_logo_64x64.png</PackageIcon>
<Version>0.1.8</Version>
<Version>0.1.9</Version>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down
1 change: 1 addition & 0 deletions Src/FluentEmailer.Core/FluentEmailer.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<Description>Send emails very easily. Use razor templates, smtp, embedded files, all without hassle. This is a Base Package and includes just the domain model, very basic defaults, and is also included with every other FluentEmailer package.</Description>

<Authors>Marco A T Ribeiro</Authors>
<Product>FluentEmailer</Product>
Expand Down
26 changes: 14 additions & 12 deletions Src/Renderers/FluentEmailer.Liquid/FluentEmailer.Liquid.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Description>Generate emails using Liquid templates. Uses the Fluid project under the hood.</Description>
<PackageTags>$(PackageTags);liquid</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Fluid.Core" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fluid.Core" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\FluentEmailer.Core\FluentEmailer.Core.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FluentEmailer.Core\FluentEmailer.Core.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions Src/Renderers/FluentEmailer.Liquid/LiquidRendererOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LiquidRendererOptions
/// <remarks>
/// This API creates dependency on Fluid.
/// </remarks>
public Action<TemplateContext, object>? ConfigureTemplateContext { get; init; }
public Action<TemplateContext, object>? ConfigureTemplateContext { get; set; }

/// <summary>
/// Text encoder to use. Defaults to <see cref="HtmlEncoder"/>.
Expand All @@ -19,7 +19,7 @@ public class LiquidRendererOptions
/// <summary>
/// File provider to use, used when resolving references in templates, like master layout.
/// </summary>
public IFileProvider? FileProvider { get; init; }
public IFileProvider? FileProvider { get; set; }

/// <summary>
/// Set custom Template Options for Fluid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Description>Send emails via MailerSend using their REST API</Description>
<PackageTags>$(PackageTags);mailersend</PackageTags>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\FluentEmailer.Core\FluentEmailer.Core.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FluentEmailer.Core\FluentEmailer.Core.csproj" />
</ItemGroup>

</Project>
18 changes: 10 additions & 8 deletions Src/Senders/FluentEmailer.Smtp/FluentEmailer.Smtp.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Description>Send emails via SMTP with a Fluent API.</Description>
<PackageTags>$(PackageTags);smtp</PackageTags>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\FluentEmailer.Core\FluentEmailer.Core.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FluentEmailer.Core\FluentEmailer.Core.csproj" />
</ItemGroup>

</Project>

0 comments on commit 6d76d11

Please sign in to comment.