Altinn.Dd.Correspondence
2.1.2-alpha
See the version list below for details.
dotnet add package Altinn.Dd.Correspondence --version 2.1.2-alpha
NuGet\Install-Package Altinn.Dd.Correspondence -Version 2.1.2-alpha
<PackageReference Include="Altinn.Dd.Correspondence" Version="2.1.2-alpha" />
<PackageVersion Include="Altinn.Dd.Correspondence" Version="2.1.2-alpha" />
<PackageReference Include="Altinn.Dd.Correspondence" />
paket add Altinn.Dd.Correspondence --version 2.1.2-alpha
#r "nuget: Altinn.Dd.Correspondence, 2.1.2-alpha"
#:package Altinn.Dd.Correspondence@2.1.2-alpha
#addin nuget:?package=Altinn.Dd.Correspondence&version=2.1.2-alpha&prerelease
#tool nuget:?package=Altinn.Dd.Correspondence&version=2.1.2-alpha&prerelease
Altinn.Dd.Correspondence
A .NET library for sending correspondence through Altinn 3 Correspondence API. This library follows Altinn 3 patterns for HttpClient registration with Maskinporten authentication.
Quick Start
1. Install Packages
dotnet add package Altinn.Dd.Correspondence
2. Configure Settings
Add to your appsettings.json:
{
"DdConfig": {
"MaskinportenSettings": {
"ClientId": "your-client-id",
"Environment": "test",
"EncodedJwk": "your-base64-encoded-jwk"
},
"ResourceId": "oed-correspondence",
"Environment": "Development"
}
}
Configuration Details:
ClientId: Your Maskinporten client ID (required)Environment: Either "test" or "prod" for Maskinporten environment (optional)EncodedJwk: Base64-encoded JWK of your Maskinporten clients secret (required)EnableDebugLogging: Optional flag to emit verbose Maskinporten diagnostics (optional)ResourceId: Id of your registered resource in Resource Registry (e.g., "oed-correspondence") (required)Environment: Environment you target in Altinn 3 (e.g., "Development", "Staging", "Production") (optional)
Note: The scope "altinn:serviceowner altinn:correspondence.write" is hardcoded in the library - you don't need to specify it. However, your Maskinporten client needs to have that scope registered.
3. Register Service
In your Program.cs or Startup.cs:
using Altinn.Dd.Correspondence.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
// In ConfigureServices or builder.Services
services.AddDdCorrespondenceService("DdConfig");
AddDdCorrespondenceServiceenforces the required correspondence scope (altinn:serviceowner altinn:correspondence.write) and wires up a Maskinporten-enabledHttpClientwith Polly-based retries. Consumers only need to supply environment-specific credentials. SetEnableDebugLoggingin configuration when troubleshooting.
4. Use the Service
Inject IDdCorrespondenceService into your classes:
public class MyService
{
private readonly IDdCorrespondenceService _correspondenceService;
public MyService(IDdCorrespondenceService correspondenceService)
{
_correspondenceService = correspondenceService;
}
public async Task SendCorrespondenceAsync()
{
var messageDetails = new DdCorrespondenceDetails
{
Recipient = "123456789", // Organization number
Title = "Important Notice",
Summary = "A brief summary",
Body = "The full message body",
Sender = "Your Organization",
Notification = new NotificationDetails
{
EmailSubject = "New message in Altinn",
EmailBody = "You have received a new message.",
SmsText = "New message in Altinn. Log in to read."
}
};
var receipt = await _correspondenceService.SendMessage(messageDetails);
}
}
Features
What the library does for you:
- Automatic Maskinporten authentication via
Altinn.ApiClients.Maskinporten - Hardcoded scope for correspondence API (no need to configure)
- Resilient HTTP client with Polly retry policy (exponential backoff)
- Automatic organization number formatting
- Idempotency support to prevent duplicate messages
Complete Example
See the SendDdCorrespondence project in this repository for a complete working example.
API Reference
Error Handling
try
{
// Pattern matching example
var receipt = await _correspondenceService.SendCorrespondence(messageDetails);
var result = receipt.Match(
onSuccess: receipt => $"Woho {receipt.IdempotencyKey}",
onFailure: error => $"Buhu {error}");
Console.WriteLine(result);
// Without pattern matching
var receipt2 = await messagingService.SendCorrespondence(messageDetails);
if (receipt2.IsSuccess)
{
Console.WriteLine($"Woho {receipt2.Receipt!.IdempotencyKey}");
}
else if (receipt2.IsFailure)
{
Console.WriteLine($"Buhu {receipt2.Error}");
}
}
catch (Exception ex)
{
// Handle API errors
Console.WriteLine($"Error: {ex.Message}");
}
Retry Logic
The service automatically retries failed requests with exponential backoff to handle transient network and API errors.
Retry Configuration:
- Retry count: 3 additional attempts (initial attempt + 3 retries)
- Backoff strategy: Exponential (2s, 4s, 8s delays between retries)
- Retried exceptions/status codes:
HttpRequestException,TaskCanceledException,SocketException- HTTP 408 (Request Timeout)
- HTTP 429 (Too Many Requests)
- HTTP 5xx status codes
Retry Behavior:
- Retries execute transparently without duplicate messages thanks to the API’s idempotency keys
- After all retries are exhausted, the original exception is surfaced to the caller
Example Implementation
SendDdCorrespondence Project
This repository includes a working example project called SendDdCorrespondence that demonstrates:
- Full correspondence sending workflow
Key features of the example:
- Includes proper error handling and logging
- Ready-to-run console application for testing
To use the example:
- Navigate to the
SendDdCorrespondenceproject - Configure your
appsettings.jsonwith your settings - Run
dotnet runto test correspondence sending
This example serves as both a testing tool and a reference implementation for integrating the Altinn.Dd.Correspondence package into your applications.
Migration from Altinn.Oed.Messaging
Overview
This guide covers migrating from Altinn.Oed.Messaging to Altinn.Dd.Correspondence (Altinn 3). The new package keeps the same high-level service contract while simplifying the receipt model.
Prerequisites
Altinn.Dd.Correspondencev2.0.0 (supports net10.0)- .NET 10.0+
- Maskinporten integration configured in your app
Step 1: Update Package References
<PackageReference Include="Altinn.Dd.Correspondence" Version="2.0.0" />
Step 2: Update Service Registration
Remove old registration:
services.AddSingleton<IOedMessagingService, OedMessagingService>();
services.AddTransient<BearerTokenHandler>();
services.AddHttpClient<IOedMessagingService, OedMessagingService>()
.AddHttpMessageHandler<BearerTokenHandler>();
Replace with new registration:
// Register correspondence services
services.AddDdCorrespondenceService("DdConfig");
Step 4: Update Configuration
Old format:
{
"AltinnMessagingSettings": {
"BaseUrl": "https://your-altinn3-url",
"CorrespondenceSettings": {
"Sender": "Your Sender Name"
}
}
}
New format:
{
"DdConfig": {
"MaskinportenSettings": {
"ClientId": "my-client-id",
"Environment": "test",
"EncodedJwk": "my-encoded-jwk",
"EnableDebugLogging": false
},
"ResourceId": "my-resource-id",
"Environment": "development"
}
}
GitHub Workflow
This package uses an automated GitHub Actions workflow for building and publishing NuGet packages.
Workflow Triggers
The workflow (release-correspondence.yaml) triggers on:
- Manual dispatch: You can manually trigger the workflow from the GitHub Actions tab
- Tagged releases: When you create a tag starting with
correspondence-v(e.g.,correspondence-v1.0.0)
Deployment Process
- Development: Push changes to any branch - workflow will NOT run
- Testing: Use manual workflow dispatch to test builds without publishing
- Release: Create a tag like
correspondence-v1.0.0to publish to NuGet.org
Creating a Release
To publish a new version to NuGet.org:
# Create and push a tag
git tag correspondence-v1.0.0
git push origin correspondence-v1.0.0
The workflow will automatically:
- Build and test the package
- Create NuGet package with debug symbols
- Publish to NuGet.org (requires
NUGET_ORG_API_KEYsecret)
Workflow Features
- Target Framework: Builds for
net8.0 - Testing: Runs all unit and integration tests before packaging
- Debug symbols: Includes
.snupkgfiles for debugging - Artifact upload: Non-tagged builds create downloadable artifacts
- Independent deployment: Only deploys when Correspondence package changes
License
Same as parent repository.
| 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 is compatible. 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 is compatible. 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. |
-
net10.0
- Altinn.ApiClients.Maskinporten (>= 9.2.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Extensions.Http.Polly (>= 10.0.2)
- Polly (>= 8.6.5)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net8.0
- Altinn.ApiClients.Maskinporten (>= 9.2.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Extensions.Http.Polly (>= 10.0.2)
- Polly (>= 8.6.5)
-
net9.0
- Altinn.ApiClients.Maskinporten (>= 9.2.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Extensions.Http.Polly (>= 10.0.2)
- Polly (>= 8.6.5)
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 |
|---|---|---|
| 2.2.0 | 157 | 8/27/2026 |
| 2.1.2-alpha | 732 | 2/18/2026 |
| 2.1.1-alpha | 127 | 2/18/2026 |
| 2.0.10-alpha | 957 | 2/9/2026 |
| 2.0.9-alpha | 128 | 2/6/2026 |
| 2.0.5-alpha | 702 | 2/5/2026 |
| 2.0.4-alpha | 126 | 2/5/2026 |
| 2.0.3-alpha | 127 | 2/5/2026 |
| 2.0.2-alpha | 158 | 1/29/2026 |
| 2.0.0-alpha | 135 | 1/26/2026 |
| 1.0.1 | 573 | 11/13/2025 |
| 1.0.0 | 1,015 | 10/29/2025 |