Welcome to the Secure Mail Server Docs repository! This project provides comprehensive documentation for setting up a private and secure mail server. Our guides cover everything you need to know about configuring your mail server using Haraka, Mailcow, DNS settings, firewall rules, Wireguard VPN, and Caddy for enhanced security and reliability.
- Introduction
- Getting Started
- Setting Up Haraka
- Configuring Mailcow
- DNS Configuration
- Firewall Rules
- Wireguard VPN Setup
- Caddy Configuration
- Security Best Practices
- Contributing
- License
In today’s digital world, maintaining privacy and security in email communication is crucial. This documentation aims to guide you through the process of setting up a secure mail server that you can host yourself. With the right tools and configurations, you can ensure that your emails remain private and secure.
To begin, you will need a server running a Linux distribution. This guide assumes you have basic knowledge of Linux commands. Ensure that your server meets the following requirements:
- A Linux server (Ubuntu, CentOS, etc.)
- Sufficient resources (CPU, RAM, Disk Space)
- Basic understanding of networking
- Domain Name: You need a registered domain name for your mail server.
- Server Access: SSH access to your server.
- Root Privileges: Ensure you have root or sudo privileges on your server.
Haraka is a lightweight, high-performance SMTP server written in Node.js. Follow these steps to set it up:
-
Install Node.js:
sudo apt update sudo apt install nodejs npm
-
Install Haraka:
sudo npm install -g Haraka
-
Create a Haraka Instance:
mkdir /etc/haraka cd /etc/haraka haraka -i .
-
Configure Haraka: Edit the
config/smtp.ini
file to set up your SMTP settings. -
Start Haraka:
haraka -c /etc/haraka
For detailed configuration options, refer to the Haraka documentation.
Mailcow is a full-featured mail server suite. Here’s how to set it up:
-
Clone Mailcow Repository:
git clone https://github.com/mailcow/mailcow-dockerized.git cd mailcow-dockerized
-
Configure Mailcow: Copy the sample configuration file:
cp mailcow.conf.example mailcow.conf
Edit
mailcow.conf
to include your domain and other settings. -
Start Mailcow:
docker-compose up -d
-
Access Mailcow Admin Panel: Open your web browser and navigate to
http://your-domain.com
.
For more details, visit the Mailcow documentation.
Proper DNS configuration is vital for your mail server to function correctly. Here are the essential DNS records you need:
- A Record: Points your domain to your server’s IP address.
- MX Record: Directs email to your mail server.
- SPF Record: Helps prevent spammers from sending messages on behalf of your domain.
- DKIM Record: Provides a method for validating the authenticity of your emails.
- DMARC Record: Helps protect your domain from unauthorized use.
Example DNS records:
A record: mail.your-domain.com -> your-server-ip
MX record: your-domain.com -> mail.your-domain.com
SPF record: v=spf1 a mx ~all
DKIM record: (your DKIM key)
DMARC record: v=DMARC1; p=none; rua=mailto:postmaster@your-domain.com
Setting up firewall rules is crucial for securing your mail server. Here’s how to configure your firewall:
-
Allow SMTP:
sudo ufw allow 25
-
Allow IMAP:
sudo ufw allow 143
-
Allow POP3:
sudo ufw allow 110
-
Allow HTTPS (for Caddy):
sudo ufw allow 443
-
Enable the Firewall:
sudo ufw enable
Using a VPN adds an extra layer of security. Follow these steps to set up Wireguard:
-
Install Wireguard:
sudo apt install wireguard
-
Generate Keys:
wg genkey | tee privatekey | wg pubkey > publickey
-
Configure Wireguard: Edit the configuration file
/etc/wireguard/wg0.conf
:[Interface] PrivateKey = <your-private-key> Address = 10.0.0.1/24 [Peer] PublicKey = <peer-public-key> AllowedIPs = 10.0.0.2/32
-
Start Wireguard:
sudo wg-quick up wg0
-
Enable Wireguard on Boot:
sudo systemctl enable wg-quick@wg0
For more details, refer to the Wireguard documentation.
Caddy is a powerful web server that automatically manages SSL certificates. Here’s how to set it up:
-
Install Caddy:
sudo apt install caddy
-
Create a Caddyfile: Create a file at
/etc/caddy/Caddyfile
with the following content:your-domain.com { reverse_proxy localhost:your-mail-server-port }
-
Start Caddy:
sudo systemctl start caddy
-
Enable Caddy on Boot:
sudo systemctl enable caddy
For further information, visit the Caddy documentation.
- Regular Updates: Keep your server and software updated.
- Use Strong Passwords: Enforce strong password policies for user accounts.
- Backup Regularly: Implement a backup strategy for your mail server data.
- Monitor Logs: Regularly check server logs for unusual activity.
- Implement 2FA: Use two-factor authentication where possible.
We welcome contributions to improve this documentation. If you find any issues or have suggestions, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For the latest releases, check the Releases section.
Thank you for using the Secure Mail Server Docs! We hope this documentation helps you set up a secure and reliable mail server.