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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alva.ServiceKit.EmailService.Azure" Version="3.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Alva.ServiceKit.EmailService.Azure" Version="3.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Alva.ServiceKit.EmailService.Azure" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Alva.ServiceKit.EmailService.Azure --version 3.1.4
                    
#r "nuget: Alva.ServiceKit.EmailService.Azure, 3.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Alva.ServiceKit.EmailService.Azure@3.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Alva.ServiceKit.EmailService.Azure&version=3.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Alva.ServiceKit.EmailService.Azure&version=3.1.4
                    
Install as a Cake Tool

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:

  • content is treated as HTML by the Azure implementation.
  • message.ToAddresses supports multiple recipients.
  • message.Attachments is supported (converted internally to Azure's attachment format).
  • The SenderAddress from configuration is always used as the "From" address — any FromAddresses set on EmailMessage are 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.4 144 7/9/2026
3.1.3 118 7/6/2026
3.1.2 117 7/3/2026