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.Mailgun - Send emails via MailGun's REST API.
FluentEmail.SendGrid - Send email via the SendGrid API.
Usage
You can choose which renderer and sender you would like to use, or build your own inheriting from ITemplateRenderer and ISender.
Basic Usage
var email = Email
.From("[email protected]")
.To("[email protected]", "bob")
.Subject("hows it going bob")
.Body("yo dawg, sup?")
.Send();
Using a template
// Using Razor templating package
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" });
Sending Emails
// Using Smtp Sender package
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.
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
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);
More Info
http://lukencode.com/2011/04/30/fluent-email-now-supporting-razor-syntax-for-templates/
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