Zetian.Storage 1.0.6

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

Zetian.Storage - Core Storage Abstractions

NuGet-Version NuGet-Download License

Core storage abstraction layer for Zetian SMTP Server. Provides essential interfaces, base classes, and contracts for building custom message storage providers. This package serves as the foundation for all Zetian storage implementations.

⚡ Features

  • 🔄 Retry Logic - Built-in retry mechanisms for reliability
  • 🧩 Extensible - Easy to create custom storage providers
  • 📊 Attachment Handling - Standardized attachment storage
  • 🚀 High Performance - Optimized for SMTP message handling
  • 🔧 Base Classes - Ready-to-use base configurations and helpers
  • 📦 Modular Design - Install only the storage providers you need
  • 🗜️ Compression Support - Optional message body compression
  • 🎯 Clean Abstractions - Well-defined interfaces for storage implementations

📦 Installation

# Install the core package (required for custom providers)
dotnet add package Zetian
dotnet add package Zetian.Storage

🚀 Available Storage Providers

Choose from our pre-built storage providers:

Cache Storage

☁️ Cloud Storage

💾 Database Storage

🎯 Quick Start

Using a Storage Provider

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

// Configure SMTP server with SQL Server storage
var server = new SmtpServerBuilder()
    .Port(25)
    .WithSqlServerStorage(
        "Server=localhost;Database=SmtpStorage;Integrated Security=true;",
        config =>
        {
            config.MaxMessageSizeMB = 25;
            config.AutoCreateTables = true;
            config.CompressMessageBody = true;
        })
    .Build();

await server.StartAsync();

🛠️ Core Interfaces

IMessageStore

The main interface all storage providers must implement:

public interface IMessageStore
{
    /// <summary>
    /// Save the given message to the underlying storage system
    /// </summary>
    Task<bool> SaveAsync(
        ISmtpSession session,
        ISmtpMessage message,
        CancellationToken cancellationToken = default);
}

BaseStorageConfiguration

Base configuration class for all storage providers:

public abstract class BaseStorageConfiguration
{
    public double MaxMessageSizeMB { get; set; } = 25.0;
    public bool CompressMessageBody { get; set; } = false;
    public bool EnableRetry { get; set; } = true;
    public int MaxRetryAttempts { get; set; } = 3;
    public int RetryDelayMs { get; set; } = 1000;
    public int ConnectionTimeoutSeconds { get; set; } = 30;
    public bool LogErrors { get; set; } = true;
}

📝 Creating Custom Storage Providers

Step 1: Implement IMessageStore

using Zetian.Abstractions;

public class MyCustomMessageStore : IMessageStore
{
    private readonly MyCustomConfiguration _config;
    
    public MyCustomMessageStore(MyCustomConfiguration config)
    {
        _config = config;
    }
    
    public async Task<bool> SaveAsync(
        ISmtpSession session,
        ISmtpMessage message,
        CancellationToken cancellationToken = default)
    {
        // Your implementation
        try
        {
            // Save message to your storage
            await SaveToCustomStorageAsync(session, message);
            return true;
        }
        catch
        {
            return false;
        }
    }
}

Step 2: Create Configuration Class

using Zetian.Storage.Configuration;

public class MyCustomConfiguration : BaseStorageConfiguration
{
    public string ConnectionString { get; set; } = string.Empty;
    public string TableName { get; set; } = "SmtpMessages";
    public bool UseEncryption { get; set; } = false;
    // Add custom properties
}

Step 3: Create Extension Method

using Zetian.Server;
using Zetian.Storage.Extensions;
using Microsoft.Extensions.Logging;

public static class MyCustomStorageExtensions
{
    public static SmtpServerBuilder WithMyCustomStorage(
        this SmtpServerBuilder builder,
        string connectionString,
        Action<MyCustomConfiguration>? configure = null)
    {
        var configuration = new MyCustomConfiguration
        {
            ConnectionString = connectionString
        };
        
        configure?.Invoke(configuration);
        configuration.Validate();
        
        ILogger<MyCustomMessageStore>? logger = builder.GetLogger<MyCustomMessageStore>();
        var store = new MyCustomMessageStore(configuration, logger);
        
        return builder.MessageStore(store);
    }
}

Step 4: Use Your Custom Provider

var server = new SmtpServerBuilder()
    .Port(25)
    .WithMyCustomStorage(
        "custom://localhost",
        config =>
        {
            config.TableName = "EmailArchive";
            config.UseEncryption = true;
        })
    .Build();

🎨 Advanced Patterns

Implementing Compression

protected byte[] CompressData(byte[] data)
{
    if (!_config.CompressMessageBody || data.Length < 1024)
        return data;
        
    using var output = new MemoryStream();
    using (var gzip = new GZipStream(output, CompressionMode.Compress))
    {
        gzip.Write(data, 0, data.Length);
    }
    return output.ToArray();
}

Implementing Retry Logic

protected async Task<T> ExecuteWithRetryAsync<T>(
    Func<Task<T>> operation,
    CancellationToken cancellationToken = default)
{
    int attempts = 0;
    
    while (attempts < _config.MaxRetryAttempts)
    {
        try
        {
            return await operation();
        }
        catch (Exception ex) when (_config.EnableRetry && attempts < _config.MaxRetryAttempts - 1)
        {
            attempts++;
            await Task.Delay(_config.RetryDelayMs, cancellationToken);
            
            if (_config.LogErrors)
            {
                _logger?.LogWarning(
                    "Retry attempt {Attempt} after error: {Error}",
                    attempts, ex.Message);
            }
        }
    }
    
    throw new StorageException($"Operation failed after {attempts} attempts");
}

🔧 Best Practices

Storage Provider Guidelines

  1. Validation - Validate input parameters
  2. Cancellation - Respect cancellation tokens
  3. Async/Await - Use async operations throughout
  4. Logging - Use structured logging for debugging
  5. Resource Cleanup - Properly dispose of resources
  6. Connection Pooling - Reuse connections when possible
  7. Error Handling - Implement comprehensive error handling
  8. Thread Safety - Ensure your implementation is thread-safe

Performance Tips

  • Async I/O - Use async file/network operations
  • Caching - Cache frequently accessed messages
  • Connection Reuse - Maintain connection pools
  • Compression - Enable for large message bodies
  • Indexing - Create appropriate indexes for queries
  • Batch Operations - Process multiple messages in batches

📋 Requirements

  • .NET 6.0, 7.0, 8.0, 9.0, or 10.0
  • Zetian SMTP Server package
  • Storage-specific dependencies based on provider

📚 Documentation & Support

📄 License

MIT License - see LICENSE


Built with ❤️ for the .NET community

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Zetian.Storage:

Package Downloads
Zetian.Storage.AmazonS3

Amazon S3 and S3-compatible storage provider for Zetian SMTP Server. Delivers enterprise-grade cloud message persistence to AWS S3 or compatible services (MinIO, Wasabi, DigitalOcean Spaces) with advanced features including automatic lifecycle rules for cost optimization, server-side KMS encryption, object versioning, transfer acceleration, customizable storage classes, IAM role support, and built-in compression. Ideal for AWS-based deployments requiring durable, cost-effective message archival with 99.999999999% durability and global accessibility.

Zetian.Storage.SqlServer

SQL Server storage provider for Zetian SMTP Server. Provides high-performance message persistence to Microsoft SQL Server databases with features including automatic table creation, message compression, separate attachment storage, retry logic, and full ACID compliance. Perfect for enterprise environments requiring reliable message storage with SQL Server infrastructure.

Zetian.Storage.AzureBlob

Azure Blob Storage provider for Zetian SMTP Server. Provides scalable, cloud-native message persistence to Microsoft Azure with enterprise features including hierarchical blob organization, automatic access tier management (Hot/Cool/Archive), Azure AD authentication, soft delete protection, blob tagging for advanced searching, server-side encryption, and built-in compression. Perfect for cloud-first applications requiring unlimited storage capacity, geo-redundancy, and seamless Azure ecosystem integration.

Zetian.Storage.PostgreSQL

PostgreSQL storage provider for Zetian SMTP Server. Provides enterprise-grade message persistence to PostgreSQL databases with advanced features including JSONB header storage, automatic table partitioning, GIN indexing for full-text search, message compression, and built-in retry logic. Ideal for high-volume environments requiring scalable, open-source database storage with powerful querying capabilities.

Zetian.Storage.MongoDB

MongoDB NoSQL storage provider for Zetian SMTP Server. Provides flexible, schema-less message persistence with advanced features including GridFS for large attachment storage, automatic TTL-based message expiration, horizontal sharding for scalability, text indexing for full-text search, and built-in compression. Perfect for modern applications requiring flexible data models, automatic scaling, and document-oriented storage without rigid schemas.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 409,685 12/1/2025
1.0.5 220 11/1/2025
1.0.4 317 10/29/2025
1.0.3 512 10/25/2025
1.0.2 109 10/25/2025
1.0.1 97 10/25/2025
1.0.0 226,535 10/25/2025

All changes are detailed at https://zetian.soferity.com/changelog.