Skip to content

Commit 7cb597a

Browse files
committed
Commit
1 parent 1eaa53f commit 7cb597a

File tree

1 file changed

+207
-48
lines changed

1 file changed

+207
-48
lines changed

README.md

Lines changed: 207 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,234 @@
1-
# Private and Secure Email Server Architecture
1+
# Secure Mail Server Documentation 📧🔒
22

3-
## The Journey of Self-Hosting Email
3+
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.
44

5-
When I first embarked on the journey of self-hosting my email server, I encountered a common narrative in the tech community: "Don't do it." Friends and YouTube experts alike warned me about two major challenges:
5+
[![Download Releases](https://img.shields.io/badge/Download%20Releases-blue.svg)](https://github.com/mariasaragih/secure-mail-server-docs/releases)
66

7-
1. **Complexity**: Setting up a private email server is notoriously complex, they said. And they weren't entirely wrong. The process is indeed complex, but perhaps not for the reasons we think. The complexity isn't inherent to the technology itself, but rather stems from a lack of modern, user-friendly tools and documentation. It's almost as if the tech industry has collectively decided that self-hosting email is a lost cause, leading to a self-fulfilling prophecy where the tools and guides remain outdated and complicated.
7+
## Table of Contents
88

9-
2. **Deliverability**: "Your emails will never reach inboxes," they cautioned. "Major providers like Gmail and Outlook maintain strict whitelists and blacklists, automatically flagging emails from residential IPs as spam." This, however, turned out to be a myth. Through careful architecture and proper configuration, it's not only possible but achievable to reach 100% deliverability rates - sometimes even better than commercial solutions. The key lies in understanding the email ecosystem and implementing the right infrastructure.
9+
1. [Introduction](#introduction)
10+
2. [Getting Started](#getting-started)
11+
3. [Setting Up Haraka](#setting-up-haraka)
12+
4. [Configuring Mailcow](#configuring-mailcow)
13+
5. [DNS Configuration](#dns-configuration)
14+
6. [Firewall Rules](#firewall-rules)
15+
7. [Wireguard VPN Setup](#wireguard-vpn-setup)
16+
8. [Caddy Configuration](#caddy-configuration)
17+
9. [Security Best Practices](#security-best-practices)
18+
10. [Contributing](#contributing)
19+
11. [License](#license)
1020

11-
This project documents the current state of self-hosted email infrastructure, serving as a comprehensive reference for both immediate implementation and future development. By mapping out each component and requirement in detail, we create a foundation that can be used to develop more automated and simplified solutions. The architecture achieves excellent deliverability without relying on external email relay services, proving that complete email independence is possible. While the current implementation requires technical expertise, this guide aims to facilitate the creation of more user-friendly tools that will make self-hosted email accessible to everyone.
21+
## Introduction
1222

13-
This repository contains documentation for a secure email server architecture implementation. The system consists of a client-server setup with secure communication through WireGuard VPN.
23+
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.
1424

15-
## Architecture Overview
25+
## Getting Started
1626

17-
The system is composed of two main components:
27+
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:
1828

19-
1. **Client Server (Internal)**
20-
- Runs Mailcow-Dockerized
21-
- Not exposed to the internet
22-
- Communicates with the proxy server through WireGuard VPN
29+
- A Linux server (Ubuntu, CentOS, etc.)
30+
- Sufficient resources (CPU, RAM, Disk Space)
31+
- Basic understanding of networking
2332

24-
2. **Proxy Server (External)**
25-
- Has a static public IP
26-
- Exposed to the internet
27-
- Runs Haraka mail server
28-
- Handles incoming and outgoing email traffic
29-
- Forwards emails to the client server using XCLIENT
33+
### Prerequisites
3034

31-
## Setup Guide - Step by Step
35+
1. **Domain Name**: You need a registered domain name for your mail server.
36+
2. **Server Access**: SSH access to your server.
37+
3. **Root Privileges**: Ensure you have root or sudo privileges on your server.
3238

33-
Follow these steps in order to set up your secure email server:
39+
## Setting Up Haraka
3440

35-
1. **[Network Configuration](docs/network.md)** - Network architecture overview and requirements
36-
2. **[Firewall Configuration](docs/firewall.md)** - UFW setup and port forwarding
37-
3. **[WireGuard VPN Setup](docs/wireguard.md)** - Secure tunnel configuration between servers
38-
4. **[Mailcow Configuration](docs/mailcow.md)** - Internal mail server setup
39-
5. **[DNS Configuration](docs/dns.md)** - Email delivery DNS setup
40-
6. **[Haraka Mail Server Setup](docs/haraka.md)** - Proxy mail server configuration
41-
7. **[Caddy Web Server Setup](docs/caddy.md)** - Reverse proxy for web access
41+
Haraka is a lightweight, high-performance SMTP server written in Node.js. Follow these steps to set it up:
4242

43-
Each document contains detailed instructions for its specific component and will guide you to the next step.
43+
1. **Install Node.js**:
44+
```bash
45+
sudo apt update
46+
sudo apt install nodejs npm
47+
```
4448

45-
## Security Features
49+
2. **Install Haraka**:
50+
```bash
51+
sudo npm install -g Haraka
52+
```
4653

47-
- Complete network isolation of the mail server
48-
- Secure communication through WireGuard VPN
49-
- Preservation of original sender IP and headers
50-
- Minimal attack surface with controlled port exposure
54+
3. **Create a Haraka Instance**:
55+
```bash
56+
mkdir /etc/haraka
57+
cd /etc/haraka
58+
haraka -i .
59+
```
5160

52-
## Testing Environment
61+
4. **Configure Haraka**:
62+
Edit the `config/smtp.ini` file to set up your SMTP settings.
5363

54-
This architecture has been tested using Debian 12 as the operating system for both client and server components. The proxy server was deployed on a [IONOS VPS](https://www.ionos.com/servers/vps), chosen for the following reasons:
64+
5. **Start Haraka**:
65+
```bash
66+
haraka -c /etc/haraka
67+
```
5568

56-
- IONOS provides minimal VPS solutions starting at €1/month with 1GB of RAM
57-
- IONOS VPS instances come with a static public IP address with excellent reputation
58-
- The static IP significantly improves email deliverability and reduces the risk of emails being marked as spam
69+
For detailed configuration options, refer to the [Haraka documentation](https://haraka.github.io/).
5970

60-
While this setup relies on IONOS as an intermediary for the proxy server, it offers advantages over dedicated SMTP relay services (such as [MailChannels](https://www.mailchannels.com/)). Although services like MailChannels claim to respect privacy by not logging email content and purging metadata logs after 30 days, they still collect metadata about senders and recipients, and potentially have access to email content.
71+
## Configuring Mailcow
6172

62-
By self-hosting the SMTP relay through a VPS, we maintain greater control over our email infrastructure. In the future, any hosting provider that offers static IP addresses with good reputation could be used, making it possible to move to a completely independent server setup while maintaining good email deliverability.
73+
Mailcow is a full-featured mail server suite. Here’s how to set it up:
6374

64-
## License
75+
1. **Clone Mailcow Repository**:
76+
```bash
77+
git clone https://github.com/mailcow/mailcow-dockerized.git
78+
cd mailcow-dockerized
79+
```
80+
81+
2. **Configure Mailcow**:
82+
Copy the sample configuration file:
83+
```bash
84+
cp mailcow.conf.example mailcow.conf
85+
```
86+
87+
Edit `mailcow.conf` to include your domain and other settings.
88+
89+
3. **Start Mailcow**:
90+
```bash
91+
docker-compose up -d
92+
```
93+
94+
4. **Access Mailcow Admin Panel**:
95+
Open your web browser and navigate to `http://your-domain.com`.
96+
97+
For more details, visit the [Mailcow documentation](https://mailcow.email/).
98+
99+
## DNS Configuration
100+
101+
Proper DNS configuration is vital for your mail server to function correctly. Here are the essential DNS records you need:
102+
103+
1. **A Record**: Points your domain to your server’s IP address.
104+
2. **MX Record**: Directs email to your mail server.
105+
3. **SPF Record**: Helps prevent spammers from sending messages on behalf of your domain.
106+
4. **DKIM Record**: Provides a method for validating the authenticity of your emails.
107+
5. **DMARC Record**: Helps protect your domain from unauthorized use.
108+
109+
Example DNS records:
110+
```
111+
A record: mail.your-domain.com -> your-server-ip
112+
MX record: your-domain.com -> mail.your-domain.com
113+
SPF record: v=spf1 a mx ~all
114+
DKIM record: (your DKIM key)
115+
DMARC record: v=DMARC1; p=none; rua=mailto:postmaster@your-domain.com
116+
```
117+
118+
## Firewall Rules
119+
120+
Setting up firewall rules is crucial for securing your mail server. Here’s how to configure your firewall:
121+
122+
1. **Allow SMTP**:
123+
```bash
124+
sudo ufw allow 25
125+
```
126+
127+
2. **Allow IMAP**:
128+
```bash
129+
sudo ufw allow 143
130+
```
131+
132+
3. **Allow POP3**:
133+
```bash
134+
sudo ufw allow 110
135+
```
65136

66-
This project is licensed under the Creative Commons Zero v1.0 Universal (CC0) License - see the [LICENSE](LICENSE) file for details.
137+
4. **Allow HTTPS (for Caddy)**:
138+
```bash
139+
sudo ufw allow 443
140+
```
141+
142+
5. **Enable the Firewall**:
143+
```bash
144+
sudo ufw enable
145+
```
146+
147+
## Wireguard VPN Setup
148+
149+
Using a VPN adds an extra layer of security. Follow these steps to set up Wireguard:
150+
151+
1. **Install Wireguard**:
152+
```bash
153+
sudo apt install wireguard
154+
```
155+
156+
2. **Generate Keys**:
157+
```bash
158+
wg genkey | tee privatekey | wg pubkey > publickey
159+
```
160+
161+
3. **Configure Wireguard**:
162+
Edit the configuration file `/etc/wireguard/wg0.conf`:
163+
```
164+
[Interface]
165+
PrivateKey = <your-private-key>
166+
Address = 10.0.0.1/24
167+
168+
[Peer]
169+
PublicKey = <peer-public-key>
170+
AllowedIPs = 10.0.0.2/32
171+
```
172+
173+
4. **Start Wireguard**:
174+
```bash
175+
sudo wg-quick up wg0
176+
```
177+
178+
5. **Enable Wireguard on Boot**:
179+
```bash
180+
sudo systemctl enable wg-quick@wg0
181+
```
182+
183+
For more details, refer to the [Wireguard documentation](https://www.wireguard.com/).
184+
185+
## Caddy Configuration
186+
187+
Caddy is a powerful web server that automatically manages SSL certificates. Here’s how to set it up:
188+
189+
1. **Install Caddy**:
190+
```bash
191+
sudo apt install caddy
192+
```
193+
194+
2. **Create a Caddyfile**:
195+
Create a file at `/etc/caddy/Caddyfile` with the following content:
196+
```
197+
your-domain.com {
198+
reverse_proxy localhost:your-mail-server-port
199+
}
200+
```
201+
202+
3. **Start Caddy**:
203+
```bash
204+
sudo systemctl start caddy
205+
```
206+
207+
4. **Enable Caddy on Boot**:
208+
```bash
209+
sudo systemctl enable caddy
210+
```
211+
212+
For further information, visit the [Caddy documentation](https://caddyserver.com/docs/).
213+
214+
## Security Best Practices
215+
216+
1. **Regular Updates**: Keep your server and software updated.
217+
2. **Use Strong Passwords**: Enforce strong password policies for user accounts.
218+
3. **Backup Regularly**: Implement a backup strategy for your mail server data.
219+
4. **Monitor Logs**: Regularly check server logs for unusual activity.
220+
5. **Implement 2FA**: Use two-factor authentication where possible.
67221

68222
## Contributing
69223

70-
This guide was written after successfully completing this project. However, I haven't verified step-by-step from scratch that all the instructions in this guide lead to the desired outcome. There might be missing steps or room for improvement in terms of security measures and functionality.
224+
We welcome contributions to improve this documentation. If you find any issues or have suggestions, please open an issue or submit a pull request.
225+
226+
## License
227+
228+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
229+
230+
For the latest releases, check the [Releases section](https://github.com/mariasaragih/secure-mail-server-docs/releases).
231+
232+
[![Download Releases](https://img.shields.io/badge/Download%20Releases-blue.svg)](https://github.com/mariasaragih/secure-mail-server-docs/releases)
71233

72-
I am absolutely open to improving these steps if:
73-
- I missed some important security measures
74-
- I overlooked critical functionality
75-
- I forgot any important steps in the process
234+
Thank you for using the Secure Mail Server Docs! We hope this documentation helps you set up a secure and reliable mail server.

0 commit comments

Comments
 (0)