Alva.ServiceKit.EmailService.Azure
3.1.4
dotnet add package Alva.ServiceKit.EmailService.Azure --version 3.1.4
NuGet\Install-Package Alva.ServiceKit.EmailService.Azure -Version 3.1.4
<PackageReference Include="Alva.ServiceKit.EmailService.Azure" Version="3.1.4" />
<PackageVersion Include="Alva.ServiceKit.EmailService.Azure" Version="3.1.4" />
<PackageReference Include="Alva.ServiceKit.EmailService.Azure" />
paket add Alva.ServiceKit.EmailService.Azure --version 3.1.4
#r "nuget: Alva.ServiceKit.EmailService.Azure, 3.1.4"
#:package Alva.ServiceKit.EmailService.Azure@3.1.4
#addin nuget:?package=Alva.ServiceKit.EmailService.Azure&version=3.1.4
#tool nuget:?package=Alva.ServiceKit.EmailService.Azure&version=3.1.4
ServiceKit.EmailService.Azure
Azure Communication Services implementation of the Alva.ServiceKit email sender. Implements IEmailSender (from Alva.ServiceKit.EmailService.Abstractions) using the Azure.Communication.Email SDK.
Installation
dotnet add package Alva.ServiceKit.EmailService.Azure
This automatically pulls in Alva.ServiceKit.EmailService.Abstractions as a dependency.
Part 1 — Setting up the Azure resources
Before this package can send anything, an Azure Communication Services resource with a connected email domain must exist. This is a one-time setup per environment (e.g. once for development/testing, once for production).
1. Create a Communication Services resource
- Go to portal.azure.com → search "Communication Services" → Create
- Choose the Subscription and Resource Group
- Give it a name (e.g.
alva-servicekit-comms) - Select a Data location
2. Create an Email Communication Services resource
- Search "Email Communication Services" → Create
- Use the same Resource Group
- Give it a name (e.g.
alva-servicekit-email) - Data location must match the one from step 1
3. Add and verify a domain
- Inside the Email Communication Services resource → Provision domains
- For testing: use the free Azure-managed domain (
<random>.azurecomm.net) — no DNS setup, ready instantly - For production: add a custom domain and verify it via DNS (SPF/DKIM/DMARC records)
4. Connect the Email domain to the Communication Services resource
- Go back to the Communication Services resource → Email → Domains
- Connect domain → select the Email Communication Services resource and domain from steps 2-3
5. Get the Connection String
- In the Communication Services resource → Keys
- Copy the Connection String (primary or secondary)
6. Get the Sender Address
- In the Email Communication Services resource → Provision domains → click the domain
- Under MailFrom addresses, copy the address (e.g.
DoNotReply@<domain>.azurecomm.net)
Prerequisite: resource provider registration
If you get a 401 Denied by the resource provider error when sending, make sure the Microsoft.Communication resource provider is registered on the subscription:
Subscriptions → [your subscription] → Resource providers → Microsoft.Communication → Register
Part 2 — Configuring the package in your project
The sender needs two values: the connection string and the sender address from Part 1.
⚠️ Never commit these values to source control
Use one of the following instead:
Local development — .NET User Secrets:
dotnet user-secrets init
dotnet user-secrets set "EmailService:ConnectionString" "<connection-string>"
dotnet user-secrets set "EmailService:SenderAddress" "<sender-address>"
Production — environment variables or a secret manager (Azure Key Vault, GitHub Actions secrets, etc.), exposed as configuration under the same EmailService:ConnectionString / EmailService:SenderAddress keys.
appsettings.json
{
"EmailService": {
"ConnectionString": "endpoint=https://<resource-name>.communication.azure.com/;accesskey=<key>",
"SenderAddress": "DoNotReply@<your-domain>.azurecomm.net"
}
}
Dependency Injection (ASP.NET Core / generic host)
services.AddTransient<IEmailSender, AzureEmailSender>();
services.AddSingleton<IAzureEmailConfiguration>(
context.Configuration.GetSection("EmailService").Get<AzureEmailConfiguration>());
Manual configuration (no DI container)
using Microsoft.Extensions.Configuration;
using Alva.ServiceKit.EmailService.Azure;
var configuration = new ConfigurationBuilder()
.AddUserSecrets<Program>() // or AddEnvironmentVariables() in production
.Build();
var azureConfig = new AzureEmailConfiguration
{
ConnectionString = configuration["EmailService:ConnectionString"]!,
SenderAddress = configuration["EmailService:SenderAddress"]!
};
Part 3 — Usage
Once IEmailSender is registered, it can be injected anywhere:
public class AppRunner
{
private readonly IEmailSender _emailSender;
public AppRunner(IEmailSender emailSender)
{
_emailSender = emailSender;
}
public void SendTestEmail()
{
_emailSender.Send("recipient@example.com", "Test", "Test");
}
}
Or without DI:
using Alva.ServiceKit.EmailService.Abstractions;
using Alva.ServiceKit.EmailService.Azure;
var emailSender = new AzureEmailSender(azureConfig);
var message = new EmailMessage(
to: new EmailAddress { Address = "recipient@example.com", Name = "Recipient Name" },
subject: "Welcome",
content: "<h1>Hello!</h1><p>Thanks for signing up.</p>");
await emailSender.SendAsync(message);
Available methods (IEmailSender)
| Method | Description |
|---|---|
Send(EmailMessage) |
Sends synchronously, throws on failure |
Send(to, subject, content) |
Shorthand for a single recipient, synchronous |
SendAsync(EmailMessage) |
Sends asynchronously, throws on failure |
SendAsync(to, subject, content) |
Shorthand for a single recipient, async |
SendSafeAsync(EmailMessage) |
Async, swallows exceptions (fire-and-forget style) |
SendSafeAsync(to, subject, content) |
Shorthand + swallows exceptions |
Notes:
contentis treated as HTML by the Azure implementation.message.ToAddressessupports multiple recipients.message.Attachmentsis supported (converted internally to Azure's attachment format).- The
SenderAddressfrom configuration is always used as the "From" address — anyFromAddressesset onEmailMessageare not used, since Azure Communication Services requires the sender to be a verified domain address.
Version
3.1.3
Part of Alva.ServiceKit
This package is part of the Alva.ServiceKit library family.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Alva.ServiceKit.EmailService.Abstractions (>= 3.1.2)
- Azure.Communication.Email (>= 1.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.