Azure Blob Storage Provider

Scalable cloud object storage with advanced lifecycle management and Azure AD integration.

Azure Cloud Storage

Azure AD AuthAccess TiersSoft DeleteLifecycle PoliciesGeo-Redundancy

Installation

dotnet add package Zetian
dotnet add package Zetian.Storage.AzureBlob

Quick Start

QuickStart.cs
using Zetian.Server;
using Zetian.Storage.AzureBlob.Extensions;

// Basic Azure Blob Storage setup
var server = new SmtpServerBuilder()
    .Port(25)
    .WithAzureBlobStorage(
        "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;")
    .Build();

await server.StartAsync();

Azure AD Authentication

Use Azure Active Directory for secure, passwordless authentication:

AzureAD.cs
// Azure AD authentication (recommended)
var server = new SmtpServerBuilder()
    .Port(25)
    .WithAzureBlobStorageAD(
        "mystorageaccount", // Storage account name only
        config =>
        {
            config.ContainerName = "smtp-messages";
            config.UseAzureAdAuthentication = true;
        })
    .Build();

Advanced Configuration

AdvancedConfig.cs
var server = new SmtpServerBuilder()
    .Port(25)
    .WithAzureBlobStorage(
        "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;",
        config =>
        {
            config.ContainerName = "smtp-messages";
            
            // Access tiers
            config.AccessTier = BlobAccessTier.Cool;
            
            // Soft delete
            config.EnableSoftDelete = true;
            config.SoftDeleteRetentionDays = 7;
            
            // Performance
            config.CompressMessageBody = true;
            config.MaxMessageSizeMB = 100;
        })
    .Build();

Access Tiers & Lifecycle

Optimize costs with automatic tier management:

Lifecycle.json
// Automatic tier management based on age
// Hot -> Cool -> Archive

// Upload to Hot tier (immediate access)
await blobClient.SetAccessTierAsync(AccessTier.Hot);

// Move to Cool after 7 days (lower cost, slower access)
await blobClient.SetAccessTierAsync(AccessTier.Cool);

// Archive after 30 days (lowest cost, hours to retrieve)
await blobClient.SetAccessTierAsync(AccessTier.Archive);

// Lifecycle policy (automatic)
{
  "rules": [{
    "name": "MoveToArchive",
    "type": "Lifecycle",
    "definition": {
      "actions": {
        "baseBlob": {
          "tierToCool": { "daysAfterModificationGreaterThan": 7 },
          "tierToArchive": { "daysAfterModificationGreaterThan": 30 },
          "delete": { "daysAfterModificationGreaterThan": 365 }
        }
      }
    }
  }]
}

Hot Tier

$$$$

Frequent access, instant retrieval

Cool Tier

$$

Infrequent access, 30+ days

Archive Tier

$

Rare access, hours to retrieve

Query & Search

Query.cs
// Query messages using tags and metadata
var blobs = containerClient.GetBlobsAsync(
    traits: BlobTraits.Metadata | BlobTraits.Tags,
    prefix: "2024/01/");

await foreach (var blob in blobs)
{
    Console.WriteLine($"Message: {blob.Name}");
    Console.WriteLine($"Size: {blob.Properties.ContentLength}");
    Console.WriteLine($"From: {blob.Metadata["from"]}");
    Console.WriteLine($"Subject: {blob.Metadata["subject"]}");
}

// Search by tags
string query = @"""From"" = '[email protected]' AND ""ReceivedDate"" > '2024-01-01'";
var taggedBlobs = containerClient.FindBlobsByTagsAsync(query);

Configuration Options

OptionDefaultDescription
ContainerName"smtp-messages"Container name
UseAzureAdAuthenticationfalseUse Azure AD auth
EnableSoftDeletefalseEnable soft delete

Security Best Practices

Use Azure AD

Managed identities over keys

Enable Soft Delete

Protect against accidental deletion

Private Endpoints

Restrict network access

Encryption

Customer-managed keys