Zetian 1.0.15

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

Zetian - Professional SMTP Server for .NET

NuGet-Version NuGet-Download License

A professional, high-performance SMTP server library for .NET with minimal dependencies. Build custom SMTP servers with ease using a fluent API and extensible architecture.

⚡ Quick Start

Installation

dotnet add package Zetian

Basic Usage

using Zetian.Server;

// Create a basic SMTP server
using var server = SmtpServerBuilder.CreateBasic();

server.MessageReceived += (sender, e) =>
{
    Console.WriteLine($"From: {e.Message.From}");
    Console.WriteLine($"Subject: {e.Message.Subject}");
};

await server.StartAsync();
Console.WriteLine($"Server running on {server.Endpoint}");

With Authentication

using Zetian.Server;

using var server = new SmtpServerBuilder()
    .Port(587)
    .RequireAuthentication()
    .AllowPlainTextAuthentication()
    .SimpleAuthentication("user", "password")
    .Build();

await server.StartAsync();

Secure Server (TLS/SSL)

using Zetian.Server;

using var server = new SmtpServerBuilder()
    .Port(587)
    .Certificate("certificate.pfx", "password")
    .RequireSecureConnection()
    .Build();

await server.StartAsync();

🎯 Key Features

  • Security - Full TLS/SSL support with STARTTLS
  • Extensible - Plugin architecture for custom logic
  • Rate Limiting - Built-in protection against abuse
  • Multi-Framework - Supports .NET 6.0, 7.0, 8.0, 9.0, 10.0
  • Event-Driven - Rich event system for message processing
  • Composite Filters - Chain multiple filters with AND/OR logic
  • SMTPUTF8 - Full UTF-8 support for international email addresses
  • Authentication - PLAIN, LOGIN mechanisms + custom auth support
  • High Performance - Efficient async/await patterns and optimized I/O
  • Mailbox Filtering - Advanced sender/recipient filtering with domain rules
  • Message Storage - Flexible message store abstraction with file system support
  • Health Check Ready - Extensible with Zetian.HealthCheck package for monitoring

🔧 Advanced Configuration

using Zetian.Models;
using Zetian.Server;

var server = new SmtpServerBuilder()
    .Port(587)
    .ServerName("My SMTP Server")
    .MaxMessageSizeMB(25)
    .MaxConnections(50)
    .RequireAuthentication()
    .AuthenticationHandler(async (user, pass) =>
    {
        // Custom authentication logic
        return await ValidateUser(user, pass)
            ? AuthenticationResult.Succeed(user)
            : AuthenticationResult.Fail();
    })
    // New features
    .EnableSmtpUtf8()
    .WithFileMessageStore(@"C:\smtp_messages")  // Protocol-level storage
    .WithSenderDomainWhitelist("trusted1.com", "trusted2.com")  // Protocol-level filtering
    .WithSenderDomainBlacklist("spam.com", "junk.org")
    .Build();

Message Storage

// Save messages to file system with date structure (Protocol-level)
using Zetian.Server;
using Zetian.Extensions;

var server = new SmtpServerBuilder()
    .Port(25)
    .WithFileMessageStore(@"C:\mail", createDateFolders: true)  // Saves at protocol level
    .Build();

// Or use the extension method (Event-based)
server.SaveMessagesToDirectory(@"C:\mail");  // Saves via event handler

// Or use custom message store
using Zetian.Server;
using Zetian.Abstractions;

public class MongoMessageStore : IMessageStore
{
    public async Task<bool> SaveAsync(ISmtpSession session, ISmtpMessage message, CancellationToken cancellationToken)
    {
        // Save to MongoDB
        return true;
    }
}

var server = new SmtpServerBuilder()
    .MessageStore(new MongoMessageStore())
    .Build();

Mailbox Filtering

// Protocol-level domain filtering (rejects at SMTP command level)
using Zetian.Server;
using Zetian.Extensions;

var server = new SmtpServerBuilder()
    .WithSenderDomainWhitelist("company.com", "partner.com")
    .WithRecipientDomainWhitelist("mydomain.com")
    .WithSenderDomainBlacklist("spam.com")
    .Build();

// Event-based domain filtering (filters after message received)
server.AddAllowedDomains("example.com");  // Extension method
server.AddSpamFilter(new[] { "spam.com" });  // Extension method

// Custom mailbox filter
using Zetian.Server;
using Zetian.Abstractions;

public class CustomMailboxFilter : IMailboxFilter
{
    public async Task<bool> CanAcceptFromAsync(ISmtpSession session, string from, long size, CancellationToken cancellationToken)
    {
        // Custom validation logic
        return !await IsBlacklisted(from);
    }
    
    public async Task<bool> CanDeliverToAsync(ISmtpSession session, string to, string from, CancellationToken cancellationToken)
    {
        // Check if recipient exists
        return await UserExists(to);
    }
}

var server = new SmtpServerBuilder()
    .MailboxFilter(new CustomMailboxFilter())
    .Build();

Composite Filters

// Combine multiple filters with AND logic
using Zetian.Enums;
using Zetian.Server;
using Zetian.Storage;

var compositeFilter = new CompositeMailboxFilter(CompositeMode.All)
    .AddFilter(new DomainMailboxFilter().AllowFromDomains("trusted.com"))
    .AddFilter(new CustomSpamFilter())
    .AddFilter(new RateLimitFilter());

var server = new SmtpServerBuilder()
    .MailboxFilter(compositeFilter)
    .Build();

📊 Message Processing

server.MessageReceived += async (sender, e) =>
{
    var message = e.Message;
    
    // Access message details
    Console.WriteLine($"From: {message.From?.Address}");
    Console.WriteLine($"To: {string.Join(", ", message.Recipients)}");
    Console.WriteLine($"Subject: {message.Subject}");
    Console.WriteLine($"Size: {message.Size} bytes");
    
    // Get message content
    var textBody = message.TextBody;
    var htmlBody = message.HtmlBody;
    
    // Save to file
    await message.SaveToFileAsync($"{message.Id}.eml");
    
    // Reject if needed
    if (IsSpam(message))
    {
        e.Cancel = true;
        e.Response = new SmtpResponse(550, "Rejected as spam");
    }
};

🔍 Important: Two Filtering Approaches

Zetian provides two different filtering approaches:

  1. Protocol-Level Filtering (via Builder) - Rejects at SMTP command level

    • Applied during MAIL FROM/RCPT TO commands
    • More efficient, saves bandwidth
    • Use WithSenderDomainWhitelist, WithFileMessageStore etc.
  2. Event-Based Filtering (via Extensions) - Filters after message received

    • Applied after the entire message is received
    • More flexible for complex logic
    • Use AddAllowedDomains, SaveMessagesToDirectory etc.

Choose based on your needs:

  • Use Protocol-Level for early rejection and better performance
  • Use Event-Based for complex filtering logic or when you need the full message

🛡️ Extensions

Rate Limiting

server.AddRateLimiting(RateLimitConfiguration.PerHour(100));

Message Filtering (Event-Based)

server.AddSpamFilter(new[] { "spam.com", "junk.org" });
server.AddSizeFilter(10 * 1024 * 1024); // 10MB max

Domain Validation (Event-Based)

server.AddAllowedDomains("example.com", "mycompany.com");

Message Storage (Event-Based)

server.SaveMessagesToDirectory(@"C:\smtp_messages");

Protocol-Level Filtering (New)

using Zetian.Server;

var server = new SmtpServerBuilder()
    .WithFileMessageStore(@"C:\mail")  // Saves at protocol level
    .WithSenderDomainWhitelist("trusted.com")  // Rejects at MAIL FROM
    .WithRecipientDomainWhitelist("mydomain.com")  // Rejects at RCPT TO
    .Build();

📦 Requirements

  • Windows, Linux, or macOS
  • .NET 6.0, 7.0, 8.0, 9.0, or 10.0

📚 Documentation & Support

🔒 Security

Best Practices:

  • Configure rate limiting
  • Keep the library updated
  • Implement proper authentication
  • Always use TLS/SSL in production

Report Security Issues: taiizor@vegalya.com

📄 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 (8)

Showing the top 5 NuGet packages that depend on Zetian:

Package Downloads
Zetian.AntiSpam

Comprehensive anti-spam solution for Zetian SMTP Server. Features include SPF/DKIM/DMARC email authentication, Bayesian spam filtering with machine learning, RBL/DNSBL reputation checks, greylisting, custom filters, and real-time threat detection. Easy integration with flexible configuration options.

Zetian.Storage

Core storage abstraction layer for Zetian SMTP Server. Provides essential interfaces (IMessageStore) and base configurations for building custom storage providers. This package serves as the foundation for all Zetian storage implementations including SQL Server, PostgreSQL, MongoDB, Redis, and cloud storage providers.

Zetian.HealthCheck

Health check monitoring extension for Zetian SMTP Server. Provides HTTP endpoints for liveness, readiness, and detailed health status monitoring with customizable checks, metrics, and Kubernetes integration support. Perfect for production monitoring and orchestration systems.

Zetian.Relay

SMTP relay and proxy extension for Zetian SMTP Server. Features include smart host support, queue management, load balancing, and failover mechanisms.

Zetian.Monitoring

Comprehensive monitoring and metrics collection for Zetian SMTP Server. Features include real-time metrics, Prometheus/Grafana integration, OpenTelemetry support, command-level statistics, and performance monitoring.

GitHub repositories

This package is not used by any popular GitHub repositories.

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