MailKit extension for asp.net core
Install-Package NETCore.MailKit -Version 2.1.0
dotnet add package NETCore.MailKit --version 2.1.0
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
});
});
}
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("xxxx@gmail.com", "ASP.NET Core mvc send email example", "Send from asp.net core mvc action");
return View();
}
}
MIT