{"id":13430893,"url":"https://github.com/lukencode/FluentEmail","last_synced_at":"2025-03-16T06:31:34.763Z","repository":{"id":37270297,"uuid":"603405","full_name":"lukencode/FluentEmail","owner":"lukencode","description":"All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.","archived":false,"fork":false,"pushed_at":"2024-03-30T12:59:11.000Z","size":2265,"stargazers_count":3098,"open_issues_count":129,"forks_count":445,"subscribers_count":80,"default_branch":"master","last_synced_at":"2025-03-14T10:19:07.661Z","etag":null,"topics":["c-sharp","dotnet","dotnetcore","email","mailgun","sendgrid","smtp"],"latest_commit_sha":null,"homepage":"https://lukelowrey.com/dotnet-email-guide-2021/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukencode.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-04-10T01:26:18.000Z","updated_at":"2025-03-14T07:07:09.000Z","dependencies_parsed_at":"2023-02-16T02:31:13.934Z","dependency_job_id":"5be62d7f-3cc8-4910-b689-de417c600d64","html_url":"https://github.com/lukencode/FluentEmail","commit_stats":{"total_commits":275,"total_committers":68,"mean_commits":4.044117647058823,"dds":0.6545454545454545,"last_synced_commit":"e1379c4d81b7b02cf3e48cf9bd718c307215e4bb"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukencode%2FFluentEmail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukencode%2FFluentEmail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukencode%2FFluentEmail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukencode%2FFluentEmail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukencode","download_url":"https://codeload.github.com/lukencode/FluentEmail/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243558661,"owners_count":20310618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","dotnet","dotnetcore","email","mailgun","sendgrid","smtp"],"created_at":"2024-07-31T02:00:58.772Z","updated_at":"2025-03-16T06:31:34.743Z","avatar_url":"https://github.com/lukencode.png","language":"C#","readme":"![alt text](https://github.com/lukencode/FluentEmail/raw/master/assets/fluentemail_logo_64x64.png \"FluentEmail\")\n\n# FluentEmail - All in one email sender for .NET and .NET Core\nThe easiest way to send email from .NET and .NET Core. Use Razor for email templates and send using SendGrid, MailGun, SMTP and more.\n\nMaintained by Luke Lowrey - follow me  on twitter **[@lukencode](https://twitter.com/lukencode)** for updates. See my blog for a detailed guide [A complete guide to send email in .NET](https://lukelowrey.com/dotnet-email-guide-2021/) \n\n\n## Nuget Packages\n\n### Core Library\n\n* [FluentEmail.Core](src/FluentEmail.Core) - Just the domain model. Includes very basic defaults, but is also included with every other package here.\n* [FluentEmail.Smtp](src/Senders/FluentEmail.Smtp) - Send email via SMTP server.\n\n### Renderers\n\n* [FluentEmail.Razor](src/Renderers/FluentEmail.Razor) - Generate emails using Razor templates. Anything you can do in ASP.NET is possible here. Uses the [RazorLight](https://github.com/toddams/RazorLight) project under the hood. \n* [FluentEmail.Liquid](src/Renderers/FluentEmail.Liquid) - Generate emails using [Liquid templates](https://shopify.github.io/liquid/). Uses the [Fluid](https://github.com/sebastienros/fluid) project under the hood. \n\n### Mail Provider Integrations\n\n* [FluentEmail.Mailgun](src/Senders/FluentEmail.Mailgun) - Send emails via MailGun's REST API.\n* [FluentEmail.SendGrid](src/Senders/FluentEmail.SendGrid) - Send email via the SendGrid API.\n* [FluentEmail.Mailtrap](src/Senders/FluentEmail.Mailtrap) - Send emails to Mailtrap. Uses [FluentEmail.Smtp](src/Senders/FluentEmail.Smtp) for delivery.\n* [FluentEmail.MailKit](src/Senders/FluentEmail.MailKit) - Send emails using the [MailKit](https://github.com/jstedfast/MailKit) email library.\n\n## Basic Usage\n```csharp\nvar email = await Email\n    .From(\"john@email.com\")\n    .To(\"bob@email.com\", \"bob\")\n    .Subject(\"hows it going bob\")\n    .Body(\"yo bob, long time no see!\")\n    .SendAsync();\n```\n\n\n## Dependency Injection\n\nConfigure 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 \nISender and ITemplateRenderer configured using AddRazorRenderer(), AddSmtpSender() or other packages.\n\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services\n        .AddFluentEmail(\"fromemail@test.test\")\n        .AddRazorRenderer()\n        .AddSmtpSender(\"localhost\", 25);\n}\n```\nExample to take a dependency on IFluentEmail:\n\n```c#\npublic class EmailService {\n\n   private IFluentEmail _fluentEmail;\n\n   public EmailService(IFluentEmail fluentEmail) {\n     _fluentEmail = fluentEmail;\n   }\n\n   public async Task Send() {\n     await _fluentEmail.To(\"hellO@gmail.com\")\n     .Body(\"The body\").SendAsync();\n   }\n}\n\n```\n\n\n\n## Using a Razor template\n\n```csharp\n// Using Razor templating package (or set using AddRazorRenderer in services)\nEmail.DefaultRenderer = new RazorRenderer();\n\nvar template = \"Dear @Model.Name, You are totally @Model.Compliment.\";\n\nvar email = Email\n    .From(\"bob@hotmail.com\")\n    .To(\"somedude@gmail.com\")\n    .Subject(\"woo nuget\")\n    .UsingTemplate(template, new { Name = \"Luke\", Compliment = \"Awesome\" });\n```\n\n## Using a Liquid template\n\n[Liquid templates](https://shopify.github.io/liquid/) are a more secure option for Razor templates as they run in more restricted environment.\nWhile Razor templates have access to whole power of CLR functionality like file access, they also\nare more insecure if templates come from untrusted source. Liquid templates also have the benefit of being faster\nto parse initially as they don't need heavy compilation step like Razor templates do.\n\nModel properties are exposed directly as properties in Liquid templates so they also become more compact.\n\nSee [Fluid samples](https://github.com/sebastienros/fluid) for more examples.\n\n```csharp\n// Using Liquid templating package (or set using AddLiquidRenderer in services)\n\n// file provider is used to resolve layout files if they are in use\nvar fileProvider = new PhysicalFileProvider(Path.Combine(someRootPath, \"EmailTemplates\"));\nvar options = new LiquidRendererOptions\n{\n    FileProvider = fileProvider\n};\n\nEmail.DefaultRenderer = new LiquidRenderer(Options.Create(options));\n\n// template which utilizes layout\nvar template = @\"\n{% layout '_layout.liquid' %}\nDear {{ Name }}, You are totally {{ Compliment }}.\";\n\nvar email = Email\n    .From(\"bob@hotmail.com\")\n    .To(\"somedude@gmail.com\")\n    .Subject(\"woo nuget\")\n    .UsingTemplate(template, new ViewModel { Name = \"Luke\", Compliment = \"Awesome\" });\n```\n\n## Sending Emails\n\n```csharp\n// Using Smtp Sender package (or set using AddSmtpSender in services)\nEmail.DefaultSender = new SmtpSender();\n\n//send normally\nemail.Send();\n\n//send asynchronously\nawait email.SendAsync();\n```\n\n## Template File from Disk\n\n```csharp\nvar email = Email\n    .From(\"bob@hotmail.com\")\n    .To(\"somedude@gmail.com\")\n    .Subject(\"woo nuget\")\n    .UsingTemplateFromFile($\"{Directory.GetCurrentDirectory()}/Mytemplate.cshtml\", new { Name = \"Rad Dude\" });\n```\n\n## Embedded Template File\n\n**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).\n\n```xml\n\u003cMvcRazorExcludeRefAssembliesFromPublish\u003efalse\u003c/MvcRazorExcludeRefAssembliesFromPublish\u003e\n```\n\n```csharp\nvar email = new Email(\"bob@hotmail.com\")\n\t.To(\"benwholikesbeer@twitter.com\")\n\t.Subject(\"Hey cool name!\")\n\t.UsingTemplateFromEmbedded(\"Example.Project.Namespace.template-name.cshtml\", \n\t\tnew { Name = \"Bob\" }, \n\t\tTypeFromYourEmbeddedAssembly.GetType().GetTypeInfo().Assembly);\n```\n\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","C\\#","dotnet","C#","C# #","框架, 库和工具","Libraries, Frameworks and Tools","Mailing","Mail","邮件"],"sub_categories":["Mail","邮件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukencode%2FFluentEmail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukencode%2FFluentEmail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukencode%2FFluentEmail/lists"}