ASP.NET Core library for MailerSend
.NET CLI
dotnet add package MailerSend.AspNetCore
Package Manager
Install-Package MailerSend.AspNetCore
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMailerSend(options =>
{
options.ApiToken = "API-TOKEN";
options.SenderEmail = "[email protected]";
options.SenderName = "MailerSend";
});
}
}
{
"MailerSend": {
"ApiToken": "API-TOKEN",
"SenderEmail": "[email protected]",
"SenderName": "MailerSend"
}
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.Configure<MailerSendOptions>(
Configuration.GetSection("MailerSend"));
services.AddMailerSend();
}
}
public class EmailController : ControllerBase
{
private readonly MailerSendService _mailerSend;
public EmailController(MailerSendService mailerSend)
{
_mailerSend = mailerSend;
}
[HttpPost("send")]
public async Task<IActionResult> SendEmailAsync(CancellationToken ct)
{
var to = new List<Recipient>()
{
new Recipient()
{
Email = "[email protected]",
Name = "User",
Substitutions = new Dictionary<string, string>()
{
{ "var1", "value1"},
{ "var2", "value2"}
}
}
};
await _mailerSend.SendMailAsync(
to, subject: "subject", text: "Test text", cancellationToken: ct);
return Ok();
}
}