In today’s digital age, having control over your email infrastructure is more important than ever. Whether you’re a small business owner, a tech enthusiast, or someone who values privacy, self-hosting your email server can be a game-changer. Enter Stalwart Email Server—a lightweight, secure, and efficient email server solution designed to make self-hosting accessible and reliable. Written in Rust, Stalwart supports modern email protocols like SMTP, JMAP, IMAP4, and POP3, ensuring your email setup is both cutting-edge and robust.
In this guide, I’ll walk you through the entire process of setting up and configuring Stalwart Email Server, step by step. By the end, you’ll have a fully functional email server that’s secure, optimized for performance, and ready to handle your personal or business email needs. Let’s dive into this email server setup adventure!
Introduction to Stalwart Email Server
Stalwart Email Server is an open-source, all-in-one mail server solution that stands out for its simplicity, security, and modern feature set. Unlike traditional email servers that require piecing together multiple components (like MTA, message store, and spam filters), Stalwart consolidates everything into a single, efficient binary. This makes it easier to manage and maintain, especially for those new to self-hosted email.
Here’s why Stalwart is a great choice:
- Lightweight and Fast: Written in Rust, it’s memory-safe and optimized for performance.
- Secure by Design: Supports encryption-at-rest, strong transport security (DANE, MTA-STS, TLS), and automatic TLS certificate provisioning.
- Modern Protocols: Full support for SMTP, JMAP, IMAP4, and POP3, ensuring compatibility with a wide range of email clients.
- Easy Management: Comes with a web-based admin interface for hassle-free configuration and monitoring.
Whether you’re looking to host email for your domain or set up a private email service, Stalwart offers a reliable and scalable solution.
Prerequisites for Setting Up Stalwart Email Server
Before we begin the Stalwart Email Server setup, make sure you have the following in place:
- A VPS or Dedicated Server: You’ll need a server with an open port 25 (SMTP). Providers like Contabo. & rarecloud offer VPS options with unblocked port 25 and clean IP addresses, which are ideal for email servers.
- A Domain Name: Register a domain from a provider like Namecheap. This will be used for your email addresses (e.g., [email protected]).
- Basic Linux Knowledge: You should be comfortable using the command line and SSH to connect to your server.
- SSH Client: Tools like Bitvise or PuTTY for connecting to your server.
Once you have these ready, you’re all set to start the email server installation process.
Step-by-Step Installation Guide
Let’s get Stalwart Email Server up and running on your system. This section provides a detailed step-by-step guide for installing it on a Linux-based server (Ubuntu 24.04 LTS is recommended).
1. Connect to Your Server
First, connect to your VPS or dedicated server using SSH. If you’re using Ubuntu, ensure your server is up to date by running:
sudo apt update && sudo apt upgrade -y
2. Install Stalwart Email Server
Stalwart provides a convenient installation script to simplify the process. Start by creating a directory for Stalwart:
sudo mkdir /opt/stalwart-mail
Navigate to the directory and download the installation script:
cd /opt/stalwart-mail
curl --proto '=https' --tlsv1.2 -sSf https://get.stalw.art/install.sh -o install.sh
sudo sh install.sh
The installer will download and set up the necessary files. After completion, it will provide login credentials for the web interface—typically an administrator account (‘admin') and a generated password. Write these down, as you’ll need them later.
3. Access the Web Interface
Once installed, you can access the web-based admin interface at http://yourserver.org:8080/login (replace yourserver.org with your server’s IP address or domain). Log in using the credentials provided during installation.
Configuring the Server
Now that Stalwart is installed, it’s time to configure your email server using the web interface. Here’s how to set up the essential components.
1. Configure Storage Backends
Stalwart uses different stores for data, blobs, full-text search, and in-memory caching. By default, it uses RocksDB, which works well for most users. To customize this, go to Settings > Storage in the web interface. Options include PostgreSQL or MySQL, but for a basic setup, sticking with RocksDB is recommended.
2. Set Up Authentication
If you want to integrate an external directory for user authentication (like LDAP or SQL), navigate to Settings > Authentication and configure your backend. For simplicity, you can use Stalwart’s internal directory, which lets you manage users directly within the platform.
3. Configure Network Settings
Ensure your server’s hostname is correctly set in Settings > Server > Network. This should match the fully qualified domain name (FQDN) of your server, such as mail.yourdomain.com. This step is critical for email delivery and security.
Setting Up DNS Records
Proper DNS configuration is essential for email server setup to ensure reliable delivery and security. Stalwart makes this easy by generating the necessary DNS records for you.
1. Add Your Domain
In the web interface, go to Management > Directory > Domains and add your domain (e.g., yourdomain.com). Once added, Stalwart will display the required DNS records, including:
- MX Record: Points email traffic to your server (e.g., mail.yourdomain.com).
- TXT Records: Includes DKIM, SPF, and DMARC entries to authenticate your emails and prevent spoofing.
2. Update Your DNS Provider
Copy the generated DNS records and add them to your domain’s DNS settings through your provider (e.g., Namecheap or Cloudflare). This step ensures your emails are delivered properly and aren’t flagged as spam. Allow some time (up to 24 hours) for DNS propagation.
Enabling TLS for Secure Connections
Security is non-negotiable for an email server, and enabling TLS ensures encrypted connections. Here’s how to secure your Stalwart Email Server.
1. Install TLS Certificate
Stalwart supports automatic TLS certificate provisioning via Let’s Encrypt. In the web interface, go to Settings > Server > TLS and enable ACME for automatic certificate management. Follow the prompts to set it up.
If you’re using a reverse proxy like NGINX or Traefik, you can configure TLS there instead.
2. Restart the Server
After enabling TLS, restart Stalwart to apply the changes. You can do this from the web interface or via the command line:
sudo systemctl restart stalwart-mail
Adding Email Accounts and Testing
With the server configured, it’s time to add email accounts and test your setup.
1. Create Email Accounts
If you’re using the internal directory, go to Management > Directory > Accounts and create a new account (e.g., [email protected]). Set a strong password and save it securely.
2. Connect with an Email Client
Stalwart doesn’t include a built-in webmail client, so you’ll need an external email client like Thunderbird or Outlook. To set up your account in Thunderbird:
- Enter your email address and password.
- Thunderbird should automatically detect the IMAP (port 143) and SMTP (port 587) settings.
- If you encounter issues with port 587, enable “Override TLS options” in the server settings.
3. Test Sending and Receiving Emails
- Send a Test Email: Use a service like Mail-Tester to check your email’s spam score. With proper DNS and TLS setup, you can achieve a perfect 10/10 score.
- Receive Emails: Send an email from an external account (e.g., Gmail) to your new address to confirm delivery.
Troubleshooting Common Issues
Even with a smooth email server configuration, you might run into issues. Here are solutions to common problems:
- DNS Issues: Verify your MX, DKIM, and SPF records. Incorrect settings can cause delivery failures.
- TLS Configuration: If clients can’t connect securely, ensure your TLS certificate matches your server’s hostname and is properly installed.
- Authentication Failures: If login fails with certain clients (e.g., Outlook), check the server logs (/opt/stalwart-mail/logs) for errors and confirm your authentication settings.
For more assistance, consult the Stalwart documentation or community forums.
Conclusion and Additional Resources
Congratulations! You’ve successfully completed the setup and configuration of Stalwart Email Server. With its modern features, strong security, and user-friendly interface, you now have a powerful tool for managing your email infrastructure.
For further exploration and support:
Self-hosting your email server with Stalwart gives you unparalleled control, privacy, and customization. Whether it’s for personal use or a small business, you’re now equipped to handle email like a pro. Happy emailing!