PosInformatique.Foundations.Emailing.Azure provides an IEmailProvider
implementation for PosInformatique.Foundations.Emailing
based on the EmailClient from Azure.Communication.Email.
It allows you to send templated emails (created via IEmailManager) using Azure Communication Service.
You can install the package from NuGet:
dotnet add package PosInformatique.Foundations.Emailing.AzureIEmailProviderimplementation using Azure.Communication.Email.EmailClient.- Simple configuration through
AddEmailing().UseAzureCommunicationService(...). - Supports configuration via:
- Azure Communication Service connection string, or
- Azure Communication Service endpoint URI.
- Callback to configure
EmailClient/EmailClientOptions:- Authentication (managed identity, connection string, etc.).
- Retry policy, logging, diagnostics, and other Azure client options.
using Microsoft.Extensions.DependencyInjection;
using PosInformatique.Foundations.EmailAddresses;
var services = new ServiceCollection();
// Your ACS connection string
var acsConnectionString = configuration["AzureCommunicationService:ConnectionString"];
services
.AddEmailing(options =>
{
options.SenderEmailAddress = EmailAddress.Parse("no-reply@myapp.com");
// Register your templates here...
// options.RegisterTemplate(EmailTemplateIdentifiers.Invitation, invitationTemplate);
})
.UseAzureCommunicationService(acsConnectionString);You can also configure the provider using the ACS endpoint URI, and configure authentication
(for example with managed identity) and client options using the clientBuilder parameter.
using Azure.Communication.Email;
using Azure.Identity;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
var acsEndpoint = new Uri(configuration["AzureCommunicationService:Endpoint"]);
services
.AddEmailing(options =>
{
options.SenderEmailAddress = EmailAddress.Parse("no-reply@myapp.com");
// Register your templates here...
})
.UseAzureCommunicationService(
acsEndpoint,
clientBuilder =>
{
// Configure EmailClient and EmailClientOptions here
clientBuilder.ConfigureOptions((EmailClientOptions options) =>
{
// Example: configure retry, diagnostics, etc.
options.Retry.MaxRetries = 5;
});
// Example: use managed identity for authentication
clientBuilder.WithCredential(new DefaultAzureCredential());
});- Configure emailing and templates with
AddEmailing(...). - Configure the Azure provider using
UseAzureCommunicationService(...). - Inject
IEmailManagerand create an email from a template identifier. - Add recipients and models.
- Call
SendAsync(...)to send via Azure Communication Service.