NETCore.MailKit
MailKit extension for asp.net core
Install with nuget
Install-Package NETCore.MailKit -Version 2.1.0
Install with .NET CLI
dotnet add package NETCore.MailKit --version 2.1.0
How to use
Add MailKit in startup like
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
//Add MailKit
services.AddMailKit(optionBuilder =>
{
optionBuilder.UseMailKit(new MailKitOptions()
{
//get options from sercets.json
Server = Configuration["Server"],
Port = Convert.ToInt32(Configuration["Port"]),
SenderName = Configuration["SenderName"],
SenderEmail = Configuration["SenderEmail"],
// can be optional with no authentication
Account = Configuration["Account"],
Password = Configuration["Password"],
// enable ssl or tls
Security = true
});
});
}
Use EmailService like
public class HomeController : Controller
{
private readonly IEmailService _EmailService;
public HomeController(IEmailService emailService)
{
_EmailService = emailService;
}
public IActionResult Email()
{
ViewData["Message"] = "ASP.NET Core mvc send email example";
_EmailService.Send("[email protected]", "ASP.NET Core mvc send email example", "Send from asp.net core mvc action");
return View();
}
}
LICENSE
MIT