Back to articles
Security & Anti-DDoS

How to Configure Stalwart Mail Server on VPS: All-in-One Vietnamese Email Solution with Rust and AI Anti-Spam

A detailed guide to configuring Stalwart Mail Server on a VPS with an all-in-one Vietnamese email solution, using Rust for high security and AI integration to effectively block spam.

DPTCloud Engineering4 min read
How to Configure Stalwart Mail Server on VPS: All-in-One Vietnamese Email Solution with Rust and AI Anti-Spam

Introduction to Stalwart Mail Server

Stalwart Mail Server is an all-in-one email server built with Rust, known for its high performance, superior security, and AI-powered spam filtering. Its modern architecture enables automated, easy-to-configure email systems suitable for small businesses, organizations, or individuals who want full control over their email infrastructure.

In this guide, we’ll walk through configuring Stalwart Mail Server on a DPTCloud VPS, leveraging built-in security features and AI-based spam protection to ensure secure and reliable email delivery.

Prerequisites and Preparation

To get started, you’ll need:

  • A Linux-based VPS (Ubuntu 22.04 or Debian 11 recommended)
  • Root SSH access
  • A primary email domain (e.g., mail.yourdomain.com)
  • Proper DNS records set up (A, MX, SPF, DKIM, DMARC)
  • Ports 25 (SMTP), 587 (SMTP TLS), 143 (IMAP), 993 (IMAPS), 110 (POP3), and 995 (POP3S) open

Configuring Stalwart Mail Server on VPS

Follow these steps to install and configure Stalwart Mail Server:

1. Update the System

sudo apt update && sudo apt upgrade -y

2. Install Rust and Required Tools

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

3. Download and Install Stalwart Mail Server

git clone https://github.com/stalwartlabs/mail-server.git
cd mail-server
cargo build --release

4. Create Basic Configuration

Generate a `config.toml` file with the following:

[server]
hostname = "mail.yourdomain.com"
port = 25
tls = true

[smtp]
enabled = true
auth = true

[imap]
enabled = true
tls = true

[pop3]
enabled = true
tls = true

[spam]
enabled = true
ai_filter = true
whitelist = ["[email protected]"]
blacklist = ["[email protected]"]

5. Configure DNS Records

Ensure the following DNS records are properly set:

Record Type Value
A 192.0.2.1 (VPS IP)
MX mail.yourdomain.com (Priority: 10)
SPF v=spf1 ip4:192.0.2.1 ~all
DKIM Refer to Stalwart’s DKIM setup guide
DMARC v=DMARC1; p=none; rua=mailto:[email protected]

Security Hardening

Stalwart Mail Server includes multiple security features, including:

  • DDoS protection via L3/L4/L7 (integrated with DPTCloud)
  • AI-based spam detection and blocking
  • Two-factor authentication (2FA) for login
  • Automatic security updates and patching

To further secure your setup:

  • Use UFW to allow only necessary ports
  • Regularly back up configuration and email data
  • Run periodic security scans with tools like openvas or nessus

Verification and Testing

After configuration, verify your setup with the following commands:

sudo systemctl status stalwart-mail-server
telnet mail.yourdomain.com 25

Ensure the server is running and accepting SMTP connections.

Send a test email from an external account and verify inbox delivery and spam filtering effectiveness.

Troubleshooting

If you encounter issues:

  • Missing emails: Verify MX, SPF, and DKIM records
  • Spam not blocked: Check AI filter settings and whitelist/blacklist entries
  • IMAP/POP3 connection failures: Confirm port availability and TLS certificates

Refer to VPS Security in the AI Era: 10 Common Vulnerabilities and Effective Prevention for deeper insights into security risks.

References

Recommended Game Infrastructure

Recommended Game Hosting Plans For This Guide

Powered by high-clock Intel Xeon Gold 6138 / 6146, Gen4 NVMe storage & Pterodactyl Panel with Anti-DDoS.

Game Server Calculator
Xeon 6146

ECO 6146-03

126.500 ₫ / mo

VAT included

  • CPU: 400% vCPU
  • RAM: 6 GB
  • Storage: 20 GB NVMe
Xeon 6146Popular

ECO 6146-04

242.000 ₫ / mo

VAT included

  • CPU: 600% vCPU
  • RAM: 8 GB
  • Storage: 20 GB NVMe
Xeon 6146

ECO 6146-06

489.500 ₫ / mo

VAT included

  • CPU: 1000% vCPU
  • RAM: 16 GB
  • Storage: 60 GB NVMe
Instant Pterodactyl deployment in under 60s · 24/7 engineering support.Browse all 16 Game Hosting plans

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478