RREnt.FluentEmail.Core
4.0.1
Prefix Reserved
dotnet add package RREnt.FluentEmail.Core --version 4.0.1
NuGet\Install-Package RREnt.FluentEmail.Core -Version 4.0.1
<PackageReference Include="RREnt.FluentEmail.Core" Version="4.0.1" />
<PackageVersion Include="RREnt.FluentEmail.Core" Version="4.0.1" />
<PackageReference Include="RREnt.FluentEmail.Core" />
paket add RREnt.FluentEmail.Core --version 4.0.1
#r "nuget: RREnt.FluentEmail.Core, 4.0.1"
#:package RREnt.FluentEmail.Core@4.0.1
#addin nuget:?package=RREnt.FluentEmail.Core&version=4.0.1
#tool nuget:?package=RREnt.FluentEmail.Core&version=4.0.1
FluentEmail - All in one email sender for .NET and .NET Core
The easiest way to send email from .NET and .NET Core. Use Razor for email templates and send using SendGrid, MailGun, SMTP and more.
Originally forked from @lukencode. See original blog for a detailed guide A complete guide to send email in .NET.
The original project has been inactive for a while and has some issues with the latest versions of .NET Core. This fork aims to fix those issues and provide a more up-to-date version of the original project.
Nuget Packages
Core Library
FluentEmail.Core - Just the domain model. Includes very basic defaults, but is also included with every other package here.
FluentEmail.Smtp - Send email via SMTP server.
Renderers
FluentEmail.Razor - Generate emails using Razor templates. Anything you can do in ASP.NET is possible here. Uses the RazorLight project under the hood.
FluentEmail.Liquid - Generate emails using Liquid templates. Uses the Fluid project under the hood.
Mail Provider Integrations
FluentEmail.Graph - Send emails using the Microsoft Graph API.
FluentEmail.Mailgun - Send emails via MailGun's REST API.
FluentEmail.MailKit - Send emails using the MailKit email library.
FluentEmail.Mailtrap - Send emails to Mailtrap. Uses FluentEmail.Smtp for delivery.
FluentEmail.SendGrid - Send email via the SendGrid API.
Basic Usage
var email = await Email
.From("john@email.com")
.To("bob@email.com", "bob")
.Subject("hows it going bob")
.Body("yo bob, long time no see!")
.SendAsync();
Dependency Injection
Configure FluentEmail in startup.cs with these helper methods. This will inject IFluentEmail (send a single email) and IFluentEmailFactory (used to send multiple emails in a single context) with the ISender and ITemplateRenderer configured using AddRazorRenderer(), AddSmtpSender() or other packages.
public void ConfigureServices(IServiceCollection services)
{
services
.AddFluentEmail("fromemail@test.test")
.AddRazorRenderer()
.AddSmtpSender("localhost", 25);
}
Example to take a dependency on IFluentEmail:
public class EmailService {
private IFluentEmail _fluentEmail;
public EmailService(IFluentEmail fluentEmail) {
_fluentEmail = fluentEmail;
}
public async Task Send() {
await _fluentEmail.To("hellO@gmail.com")
.Body("The body").SendAsync();
}
}
Using a Razor template
// Using Razor templating package (or set using AddRazorRenderer in services)
Email.DefaultRenderer = new RazorRenderer();
var template = "Dear @Model.Name, You are totally @Model.Compliment.";
var email = Email
.From("bob@hotmail.com")
.To("somedude@gmail.com")
.Subject("woo nuget")
.UsingTemplate(template, new { Name = "Luke", Compliment = "Awesome" });
Using a Liquid template
Liquid templates 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 for more examples.
// 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("bob@hotmail.com")
.To("somedude@gmail.com")
.Subject("woo nuget")
.UsingTemplate(template, new ViewModel { Name = "Luke", Compliment = "Awesome" });
Sending Emails
// 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
var email = Email
.From("bob@hotmail.com")
.To("somedude@gmail.com")
.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.
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
var email = new Email("bob@hotmail.com")
.To("benwholikesbeer@twitter.com")
.Subject("Hey cool name!")
.UsingTemplateFromEmbedded("Example.Project.Namespace.template-name.cshtml",
new { Name = "Bob" },
TypeFromYourEmbeddedAssembly.GetType().GetTypeInfo().Assembly);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
NuGet packages (7)
Showing the top 5 NuGet packages that depend on RREnt.FluentEmail.Core:
Package | Downloads |
---|---|
RREnt.FluentEmail.Smtp
Now we're talking. Send emails via SMTP. |
|
RREnt.FluentEmail.Razor
Generate emails using Razor templates. Anything you can do in ASP.NET is possible here. Uses the RazorLight project under the hood. |
|
RREnt.FluentEmail.Mailgun
Send emails via MailGun using their REST API |
|
RREnt.FluentEmail.SendGrid
Send emails via SendGrid using their REST API |
|
RREnt.FluentEmail.MailKit
Send emails via MailKit. The SmtpClient has been deprecated and Microsoft recommends using MailKit instead. |
GitHub repositories
This package is not used by any popular GitHub repositories.