Projects Issues Blogs Broadcasts Groups Events Resources
Project

FluentEmail

.NET Core email sending

alt text

FluentEmail - All in one email sender for .NET and .NET Core

Send email from .NET or .NET Core. A bunch of useful extension packages make this dead simple and very powerful.

Packages

FluentEmail.Core - Just the domain model. Includes very basic defaults, but is also included with every other package here.

FluentEmail.Smtp - Now we're talking. Send emails via SMTP.

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.Mailtrap - Send emails to Mailtrap. Uses FluentEmail.Smtp for delivery.

FluentEmail.Mailgun - Send emails via MailGun's REST API.

FluentEmail.SendGrid - Send email via the SendGrid API.

Basic Usage

var email = Email
    	.From("john@email.com")
    	.To("bob@email.com", "bob")
    	.Subject("hows it going bob")
    	.Body("yo dawg, sup?")
		.Send();

Dependency Injection You can configure FluentEmail in startup.cs with these helper methods. This will by default 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);
}

Using a 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" });

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);

More Info

Sending email in .NET Core with FluentEmail

Development and Beta Packages

If you need a pre-release version, you can add the MyGet feed to your nuget package sources.
https://www.myget.org/F/fluentemail/api/v3/index.json

NuGet

FluentEmail.Core (fuget.org)
244,279 Total Downloads 247 Downloads Per Day Latest Version: 20,543 (August 6, 2019) Hide All Versions Show All Versions
Version Downloads Last Updated
8/6/2019 August 6, 2019
7/14/2018 July 14, 2018
7/2/2018 July 2, 2018
7/1/2018 July 1, 2018
4/25/2018 April 25, 2018
12/6/2017 December 6, 2017
11/6/2017 November 6, 2017
5/15/2017 May 15, 2017
2/6/2017 February 6, 2017
893
177
46
Website

{{ 'https://lukencode.com/2018/07/01/send-email-in-dotnet-core-with-fluent-email/' | no-protocol }}

Source

{{ 'https://github.com/lukencode/FluentEmail' | no-protocol }}

NuGet