Storage Providers

Flexible message storage with support for databases, cache, and cloud platforms.

Quick Start

Get started with message storage in seconds. Choose a provider and configure with a single line.

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

// Quick setup with SQL Server storage
var server = new SmtpServerBuilder()
    .Port(25)
    .WithSqlServerStorage(
        "Server=localhost;Database=SmtpDb;Trusted_Connection=true;")
    .Build();

await server.StartAsync();

Available Storage Providers

Core Features

Security First

Encryption at rest and in transit, secure authentication

High Performance

Optimized for SMTP workloads with batching and compression

Flexible Configuration

Fine-tune each provider with extensive configuration options

Modular Design

Install only the providers you need, keep deployments lean

Multi-Provider Setup

Combine multiple storage providers for optimal performance and reliability:

MultiProvider.cs
using Zetian.Server;
using Zetian.Storage.Redis.Extensions;
using Zetian.Storage.SqlServer.Extensions;

// Primary storage with Redis cache
var server = new SmtpServerBuilder()
    .Port(25)
    // Redis for fast cache
    .WithRedisStorage("localhost:6379", config =>
    {
        config.MessageTTLSeconds = 3600; // 1 hour cache
        config.EnablePubSub = true;
    })
    // SQL Server for persistence
    .WithSqlServerStorage(connectionString, config =>
    {
        config.AutoCreateTable = true;
        config.CompressMessageBody = true;
    })
    .Build();

Cache Layer

Use Redis for ultra-fast recent message access

Persistence Layer

SQL Server or PostgreSQL for long-term storage

Archive Layer

S3 or Azure Blob for cost-effective archival

Custom Storage Provider

Create your own storage provider by implementing the IMessageStore interface:

CustomStorage.cs
using Zetian.Abstractions;
using Zetian.Storage.Configuration;

// Create custom storage provider
public class CustomMessageStore : IMessageStore
{
    public async Task<bool> SaveAsync(
        ISmtpSession session,
        ISmtpMessage message,
        CancellationToken cancellationToken = default)
    {
        // Your custom storage logic
        await SaveToCustomBackend(message);
        return true;
    }
}

// Use custom storage
var server = new SmtpServerBuilder()
    .Port(25)
    .MessageStore(new CustomMessageStore())
    .Build();

Installation

Install only the storage providers you need:

# Core SMTP Server
dotnet add package Zetian

# Choose your storage provider(s)
dotnet add package Zetian.Storage.Redis
dotnet add package Zetian.Storage.MongoDB
dotnet add package Zetian.Storage.AmazonS3
dotnet add package Zetian.Storage.AzureBlob
dotnet add package Zetian.Storage.SqlServer
dotnet add package Zetian.Storage.PostgreSQL

Common Configuration Options

All storage providers share these base configuration options:

OptionTypeDefaultDescription
MaxMessageSizeMBdouble25.0Maximum message size in megabytes
CompressMessageBodyboolfalseEnable GZIP compression
EnableRetrybooltrueRetry on transient failures
MaxRetryAttemptsint3Maximum retry attempts
RetryDelayMsint1000Delay between retries (ms)
LogErrorsbooltrueLog storage errors

Best Practices

Choose the Right Provider

Select based on your requirements: Redis for speed, SQL for reliability, Cloud for scale.

Enable Compression

For large messages, enable compression to reduce storage costs and improve performance.

Implement Retention Policies

Configure TTL or lifecycle policies to automatically clean up old messages.

Monitor Performance

Track storage metrics and adjust configuration based on actual usage patterns.