Axi.Posta.Aspire 0.1.0

dotnet add package Axi.Posta.Aspire --version 0.1.0
                    
NuGet\Install-Package Axi.Posta.Aspire -Version 0.1.0
                    
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="Axi.Posta.Aspire" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Axi.Posta.Aspire" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Axi.Posta.Aspire" />
                    
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 Axi.Posta.Aspire --version 0.1.0
                    
#r "nuget: Axi.Posta.Aspire, 0.1.0"
                    
#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 Axi.Posta.Aspire@0.1.0
                    
#: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=Axi.Posta.Aspire&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Axi.Posta.Aspire&version=0.1.0
                    
Install as a Cake Tool

Posta .NET SDK

The .NET SDK for Posta, the self-hosted email delivery and inbound platform.

Installation

dotnet add package Posta

Quick start

using Posta.Clients;
using Posta.Models.Emails;

using var client = new PostaClient(
    "https://posta.example.com",
    "your-api-key");

SendAnEmailResponse? response = await client.Emails.SendAnEmailAsync(
    new SendAnEmailRequest
    {
        From = "Acme <hello@example.com>",
        To = ["user@example.com"],
        Subject = "Hello from Posta",
        Html = "<h1>Hello!</h1>"
    });

The client exposes typed API areas such as Emails, Templates, Campaigns, Subscribers, Inbound, Webhooks, Workspaces, and Admin.

Known string values

Properties backed by a fixed set of API values remain strings for forward compatibility. The Posta.Models.Constants namespace provides constants for discoverability and to avoid string literals:

using Posta.Models.Constants;

if (verificationResponse.Data?.Status == EmailVerificationStatuses.Valid)
{
    Console.WriteLine("The email address is valid.");
}

The available constant groups are:

  • EmailVerificationStatuses: Valid, Invalid, Risky, Disposable, and Unknown
  • UserRoles: Admin and User
  • WebhookEvents: supported email and campaign webhook events
  • SmtpSecurityModes: Permissive and Strict
  • ApiKeyScopes: Send, Read, Webhooks, and All
  • BounceTypes: Hard and Soft

They can also be used when constructing requests:

using Posta.Models.Constants;
using Posta.Models.Webhooks;

var request = new CreateWebhookRequest
{
    Url = "https://example.com/webhooks/posta",
    Events = [WebhookEvents.EmailSent, WebhookEvents.EmailFailed]
};

Configuration

Use PostaClientSettings when API-key and JWT credentials, a custom timeout, or late-bound configuration are needed:

using Posta.Clients;
using Posta.Configuration;

using var client = new PostaClient(new PostaClientSettings
{
    Endpoint = new Uri("https://posta.example.com"),
    ApiKey = "your-api-key",
    AccessToken = "optional-jwt-access-token",
    Timeout = TimeSpan.FromSeconds(30)
});

An application that manages HttpClient itself can use the constructor accepting HttpClient, IPostaCredentialProvider, and an optional custom IPostaEndpoints catalog.

Aspire integration

Install the optional client-integration package in the service that calls Posta:

dotnet add package Posta.Aspire

Register the client using the same resource name passed from the AppHost with WithReference(...):

builder.AddPostaClient("posta", settings =>
{
    settings.ApiKey = builder.Configuration["Posta:ApiKey"];
});

Resolve IPostaClient from dependency injection. Posta.Aspire reads the Aspire connection string, configures HttpClient, and enables service discovery for the logical posta host name.

Multiple Posta resources can be registered with AddKeyedPostaClient(...) and resolved through GetRequiredKeyedService<IPostaClient>(key).

Error handling

Non-successful HTTP responses throw PostaApiException. The exception contains the HTTP status code and the response body returned by Posta.

using Posta.Transport;

try
{
    await client.Emails.GetEmailDetailsAsync(
        new GetEmailDetailsRequest { Id = emailId });
}
catch (PostaApiException exception)
{
    Console.WriteLine(exception.StatusCode);
    Console.WriteLine(exception.ResponseBody);
    Console.WriteLine(exception.Error?.Code);
    Console.WriteLine(exception.Error?.Type);
    Console.WriteLine(exception.Error?.Message);
}

When an ILoggerFactory is supplied to PostaClient, non-successful responses are logged with structured properties. Client errors, including 401, 404, and 429, use Warning; 5xx responses use Error. Aspire registration uses the application's logger factory automatically. Response bodies are not written to logs.

Custom endpoints

Endpoint definitions are virtual so deployments with custom routes can override only the required operation:

using Posta.Endpoints;

public sealed class CustomPostaEndpoints : PostaEndpoints
{
    public override PostaEndpoint SendAnEmail { get; } =
        new(HttpMethod.Post, "/custom/v1/emails/send", PostaAuthentication.ApiKey);
}

API coverage

The models and operations follow Posta 0.11.0's published OpenAPI document. A few operations whose wire formats are incomplete in that document are present but marked unsupported: CSV subscriber import, HTML template import, raw RFC 5322 message download, and inbound attachment download.

Building NuGet packages

On Windows:

pack-nuget.bat

On Linux or macOS:

bash ./pack-nuget.sh

Both scripts create the Posta and Posta.Aspire packages in the artifacts directory.

Tests

Run the xUnit test suite from the repository root:

dotnet test Posta.Tests/Posta.Tests.csproj

License

Apache-2.0

Product Compatible and additional computed target framework versions.
.NET 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.  net11.0 is compatible. 
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
0.1.0 84 7/16/2026