Skip to content

ADefWebserver/BlazorSMTPForwarder

Repository files navigation

BlazorSMTPForwarder

Forward unlimited domains through SendGrid

Blog Post:

Deploy Your Own Unlimited Forwarding To SendGrid SMTP Server

image

Features

  • Unlimited Domain Forwarding
    Configure and manage email forwarding for an unlimited number of domains from a single instance.

  • SendGrid Integration
    Leverages the SendGrid API for reliable, high-deliverability email forwarding without managing complex SMTP relay infrastructure.

  • Advanced Routing Rules

    • Direct Forwarding: Map specific incoming email addresses to destination addresses.
    • Catch-All Support: Configure catch-all forwarding to handle any email sent to a domain that doesn't match a specific rule.
  • Web-Based Administration

    • Dashboard: A modern Blazor-based web interface to manage all settings and domains.
    • Inbox Viewer: View received and archived emails directly in the browser.
    • Log Viewer: Built-in interface to view server logs for monitoring and troubleshooting.
  • Robust Anti-Spam Protection

    • Integrated SPF, DKIM, and DMARC verification.
    • Spamhaus RBL (Real-time Blackhole List) integration to block known spam sources.
  • Azure Cloud Native

    • Azure Table Storage: Uses Table Storage for scalable, low-cost configuration and logging.
    • Azure Blob Storage: Archives all received emails as .eml files in Blob Storage for backup and auditing.
  • Secure Access
    The web administration interface is protected by a configurable application password to prevent unauthorized access.

image image image image image image
sequenceDiagram
    participant Program
    participant HostedService as SmtpServerHostedService
    participant Zetian as Zetian.Server (SmtpServer)
    participant Handler as ZetianMessageHandler
    participant Table as Azure Table Storage
    participant Blob as Azure Blob Storage
    participant SendGrid as SendGrid API
    participant Client as External SMTP Client

    Note over Program, HostedService: Application Startup
    Program->>HostedService: StartAsync()
    
    Note over HostedService, Table: Load Configuration
    HostedService->>Table: LoadSettingsAsync()
    Table-->>HostedService: SMTPSettings (spam, domains, SendGrid key)
    
    Note over HostedService, Zetian: Configure SMTP Server
    HostedService->>Zetian: SmtpServerBuilder().ServerName().Port().Build()
    HostedService->>Zetian: AddAntiSpam(SPF, DKIM, DMARC, RBL)
    HostedService->>Zetian: MessageReceived += Handler.HandleMessageAsync
    HostedService->>Zetian: StartAsync()
    activate Zetian

    Note over Client, Zetian: Email Transmission
    Client->>Zetian: Connect & Send Email
    
    Note right of Zetian: Anti-Spam Pipeline<br/>(SPF, DKIM, DMARC, RBL checks)
    
    Zetian->>Handler: MessageReceived event
    activate Handler

    Note over Handler, Blob: Message Processing
    Handler->>Handler: Check if Recipients are Local/Configured
    
    alt Has Configured Recipients
        opt Save to Blob Enabled
            Handler->>Blob: CreateIfNotExistsAsync(email-messages)
            Handler->>Blob: Upload .eml file
            Handler-->>Handler: Log "Message saved to blob"
        end
        
        loop For Each Recipient
            Handler->>Handler: Check Forwarding Rules
            alt Rule Exists
                Handler->>SendGrid: SendEmailAsync (Forward Message)
                SendGrid-->>Handler: 202 Accepted / Error
                Handler-->>Handler: Log Result
            end
        end
    end

    Handler-->>Zetian: Complete
    deactivate Handler

    Zetian-->>Client: SMTP Response (250 OK / Error)
    
    Note over Program, HostedService: Application Shutdown
    Program->>HostedService: StopAsync()
    HostedService->>Zetian: StopAsync()
    deactivate Zetian
Loading

About

A SMTP Server for forwading emails

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published