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.
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
Cache Storage
Cloud Storage
Database Storage
MongoDB
MongoDB NoSQL with GridFS for attachments
Zetian.Storage.MongoDBSQL Server
Microsoft SQL Server with ACID compliance
Zetian.Storage.SqlServerPostgreSQL
PostgreSQL with JSONB and partitioning support
Zetian.Storage.PostgreSQLCore 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:
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:
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.PostgreSQLCommon Configuration Options
All storage providers share these base configuration options:
| Option | Type | Default | Description |
|---|---|---|---|
| MaxMessageSizeMB | double | 25.0 | Maximum message size in megabytes |
| CompressMessageBody | bool | false | Enable GZIP compression |
| EnableRetry | bool | true | Retry on transient failures |
| MaxRetryAttempts | int | 3 | Maximum retry attempts |
| RetryDelayMs | int | 1000 | Delay between retries (ms) |
| LogErrors | bool | true | Log 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.