FluentEmail - 适用于 .NET 和 .NET Core 的邮件发送库
生活随笔
收集整理的這篇文章主要介紹了
FluentEmail - 适用于 .NET 和 .NET Core 的邮件发送库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡介
FluentEmail - 適用于 .NET 和 .NET Core 的郵件發送庫
從 .NET 和 .NET Core 發送電子郵件的最簡單方法。將 Razor 用于電子郵件模板并使用 SendGrid、MailGun、SMTP 等進行發送
Nuget包
?FluentEmail.Core - 域模型?FluentEmail.Smtp - 通過 SMTP 服務器發送電子郵件?FluentEmail.Razor - 使用 Razor 模板生成電子郵件?FluentEmail.Liquid - 使用Liquid 模板生成電子郵件?FluentEmail.Mailgun - 通過 MailGun 的 REST API 發送電子郵件?FluentEmail.SendGrid - 通過 SendGrid API 發送電子郵件?FluentEmail.Mailtrap - 向 Mailtrap 發送電子郵件。使用FluentEmail.Smtp進行傳遞?FluentEmail.MailKit - 使用MailKit電子郵件庫發送電子郵件
用法
基本用法
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();依賴注入
public?void?ConfigureServices(IServiceCollection?services) {services.AddFluentEmail("fromemail@test.test").AddRazorRenderer().AddSmtpSender("localhost",?25); }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();} }使用 Razor 模板
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"?});使用 Liquid 模板
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"?});發送電子郵件
Email.DefaultSender?=?new?SmtpSender();//send?normally email.Send();//send?asynchronously await?email.SendAsync();Github地址
https://github.com/lukencode/FluentEmail
最后大家如果喜歡我的文章,還麻煩給個關注并點個贊, 希望net生態圈越來越好!
總結
以上是生活随笔為你收集整理的FluentEmail - 适用于 .NET 和 .NET Core 的邮件发送库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AspNet Core 6.0 Json
- 下一篇: .NetCore中IdentitySer