The project consist of several packages which facilitate sending notifications. It covers the following scenarios:
-
Rendering the output message content (Current support is for handle bars using https://github.com/Antaris/FuManchu library)
-
Sending messages to multiple audiences using Smtp protocol (It has been implemented using https://github.com/jstedfast/MailKit)
Using NuGet
Install-Package LittleBlocks.Notifications
Using dotnet cli
dotnet add package LittleBlocks.Notifications
There is an extension which help to setup the service for IServiceCollection.
services.AddNotification(configuration)
which is adding the following services to the DI container
services.AddOptions().Configure<NotificationOptions>(configuration.GetSection(nameof(NotificationOptions)));
services.AddOptions().Configure<SmtpOptions>(configuration.GetSection(nameof(SmtpOptions)));
services.AddTransient<ITemplateProvider, FileBasedTemplateProvider>();
services.AddTransient<IMessagingService, MailKitMessagingService>();
services.AddTransient<ITemplateContentRenderer, HandleBarsTemplateContentRenderer>();
services.AddTransient<ITemplateRenderer, TemplateRenderer>();
services.AddTransient<INotificationService, NotificationService>();
You should notice every one of the services can be customize in order to implement something different.
Also the following sections need to be added to the appsettings.json file.
"NotificationOptions": {
"Sender": "sender email address",
"Profiles": [
{
"ProfileName": "profile name",
"Audiences": [
{"Email": "email or distribution group name" }
]
},
],
"Templates": [
{
"Name": "template name",
"Path": "template default location relative to application"
},
]
},
"SmtpOptions": {
"Server": "Smtp server name",
"LocalDomain": "LittleBlocks",
"Port": "Optional. Default to 25"
}
Then you can inject INotificationService to your classes to send the email.
Note: Use Relay Messaging so there is no setup to be made on application servers to support smtp. Also the sender can be a fake email address or even a descriptive email address.