SkillAgentSearch skills...

MailerSend.AspNetCore

ASP.NET Core library for MailerSend

Install / Use

/learn @vassilis-panos/MailerSend.AspNetCore
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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 = "mail@domain.com";
            options.SenderName = "MailerSend";
        });
    }
}

appsettings.json

{
  "MailerSend": {
    "ApiToken": "API-TOKEN",
    "SenderEmail": "mail@domain.com",
    "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 = "user@domain.com",
                Name = "User",
                Substitutions = new Dictionary<string, string>()
                {
                    { "var1", "value1"},
                    { "var2", "value2"}
                }
            }
        };

        await _mailerSend.SendMailAsync(
            to, subject: "subject", text: "Test text", cancellationToken: ct);

        return Ok();
    }
}

Related Skills

View on GitHub
GitHub Stars11
CategoryDevelopment
Updated1y ago
Forks6

Languages

C#

Security Score

75/100

Audited on Feb 17, 2025

No findings