Need help with FluentEmail?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

lukencode
1.6K Stars 262 Forks MIT License 364 Commits 67 Opened issues

Description

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.

Services available

!
?

Need anything else?

Contributors list

# 42,582
C#
mailgun
c-sharp
sendgri...
91 commits
# 72,012
dotnet-...
c-sharp
linq
Univers...
43 commits
# 14,783
.NET
mvvm-fr...
graphql...
entity-...
19 commits
# 133,117
C#
mailgun
c-sharp
sendgri...
12 commits
# 167,779
C#
mailgun
c-sharp
sendgri...
7 commits
# 85,425
C#
Xamarin
mailgun
c-sharp
6 commits
# 168,391
React
Shell
C#
mailgun
5 commits
# 95,631
PHP
mailgun
c-sharp
sendgri...
5 commits
# 207,363
C#
Shell
mailgun
c-sharp
4 commits
# 2,324
C#
.NET
c-sharp
rabbitm...
3 commits
# 265,302
C#
mailgun
c-sharp
sendgri...
2 commits
# 188,295
vanilla...
dropzon...
Vanilla...
mailgun
2 commits
# 240,568
C#
mailgun
c-sharp
sendgri...
2 commits
# 243,433
C#
mailgun
c-sharp
sendgri...
2 commits
# 263,346
C#
mailgun
c-sharp
sendgri...
2 commits
# 264,838
C#
mailgun
c-sharp
sendgri...
2 commits
# 202,429
c-sharp
F#
elastic...
sacn
2 commits
# 5,763
Objecti...
Swift
depende...
carthag...
2 commits
# 31
Atom
Electro...
Less
c-plus-...
2 commits
# 264,423
Shell
mailgun
c-sharp
.NET
1 commit

alt text

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.

Maintained by Luke Lowrey - follow me on twitter @lukencode for updates. See my blog for a detailed guide A complete guide to send email in .NET

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

Mail Provider Integrations

Basic Usage

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 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("[email protected]")
        .AddRazorRenderer()
        .AddSmtpSender("localhost", 25);
}

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("[email protected]") .To("[email protected]") .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("[email protected]") .To("[email protected]") .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("[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.

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.