8000 GitHub - ultimaweapon/composer: Send the emails from dynamic templates without re-deploying your .NET app
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Send the emails from dynamic templates without re-deploying your .NET app

License

Notifications You must be signed in to change notification settings

ultimaweapon/composer

Repository files navigation

Composer

Nuget

This is a framework for .NET to compose an email from a configured template so the email format can be update on the fly without updating the application code.

Usage

First add essential services to IServiceCollection by invoke AddComposer extension method:

services.AddComposer();

AddComposer return an object for configure Composer. The application required to provider IEmailSender and ITemplateProvider by invoke AddSender and AddTemplateProvider:

services
    .AddComposer()
    .AddSender<SenderImplementation>()
    .AddTemplateProvider<TemplateProviderImplementation>();

SMTP sender

SMTP sender is shipped with Composer so you don't need to install additional package to use it. To use SMTP sender invoke AddSmtpSender:

services
    .AddComposer()
    .AddSmtpSender(options =>
    {
        options.SmtpServer = "host";
        options.SmtpPort = 25;
    })
    .AddTemplateProvider<TemplateProviderImplementation>();

Available sender

Available template provider

Define an email

You need to create a new class that derived from Email class. Each class represents one type of email you want to send (e.g. an email to send when user has signed up).

namespace SampleApp;

using System;
using Composer;

internal sealed class RegistrationCompletedEmail : Email
{
    public static readonly Guid Id = new Guid("e8c01835-bc01-4f03-b4f7-197d0d0a3b4a");

    public RegistrationCompletedEmail(string username)
    {
        this.Username = username;
    }

    public string Username { get; }

    protected override object TemplateId => Id;

    protected override object? BuildTemplateData() => new { this.Username };
}

Send an email

Inject IEmailComposer to the class you want to send email. Then invoke ComposeAsync:

var email = new RegistrationCompletedEmail("john");

await composer.ComposeAsync("john@example.com", email, cancellationToken);

Add attachments

Override Email.BuildAttachments or Email.BuildAttachmentsAsync to provide attachments for the email.

License

MIT

About

Send the emails from dynamic templates without re-deploying your .NET app

Topics

Resources

License

Stars

Watchers

Forks

Languages

0