Skip to content

cetinbas/MailerSend.AspNetCore

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MailerSend.AspNetCore NuGet

ASP.NET Core library for MailerSend

Installation

.NET CLI

dotnet add package MailerSend.AspNetCore

Package Manager

Install-Package MailerSend.AspNetCore

Configuration

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMailerSend(options =>
        {
            options.ApiToken = "API-TOKEN";
            options.SenderEmail = "[email protected]";
            options.SenderName = "MailerSend";
        });
    }
}

appsettings.json

{
  "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();
    }
}

Dependency injection

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();
    }
}

About

ASP.NET Core library for MailerSend

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%