Intro#
To add email subscription and notification to mix-space, I plan to build my own mail server.
After searching online, I found that iRedMail is powerful, easy to use, and not too complicated to deploy. Let's do it!
If you also want to deploy it, you need to have:
- A VPS, preferably with Reverse DNS support.
- A domain name (of course)
This article is based on Ubuntu 22.04 LTS, using the domain name xxu.do as an example. You can refer to it.
Formal Installation#
System and Installation Preparation#
- Update your packages and install the required packages:
sudo apt update
sudo apt upgrade
sudo apt install wget curl sudo tar socat bind9-utils -y
- Plan to use mail.xxu.do as the mail server domain name, that is, set the VPS hostname:
vim /etc/hosts
127.0.0.1 mail.xxu.do mail # Add a line, where mail.xxu.do is the long hostname and mail is the short hostname
x.x.x.x mail.xxu.do mail # If you have your public IP address here, you can also change it to your hostname, save and exit
vim /etc/hostname
mail # Change the content inside to mail, save and exit
reboot # Restart to take effect
hostname # After execution, you should see the short hostname mail. If you see the long hostname, the settings are incorrect
hostname -f # After execution, you should see the long hostname mail.xxu.do. If you see the short hostname, the settings are incorrect
- Download and install iRedMail
wget https://github.com/iredmail/iRedMail/archive/refs/tags/1.6.8.tar.gz # As of 20240401, the latest version is 1.6.8
tar -xf iRedMail.tar.gz
cd iRedMail-1.6.8 && bash iRedMail.sh
Next, enter the graphical installation interface, use "space" to select, and "enter" to proceed. If you need to stop the installation, you can press "Ctrl+C".
1. Install, press enter
2. Installation directory, keep the default, press enter
3. Select the web server, I'm familiar with nginx, so choose nginx, press enter
4. Select the database, choose the second option MariaDB, press enter
5. Set the database password, please remember it
6. Set the domain, it cannot be the same as the hostname, in this article it is xxu.do
7. Set the administrator password, please remember it
8. Then press y all the way, after the setup is complete, use `reboot` to restart the system to take effect
Configure Domain Records#
- Resolve the mail server domain name to your VPS, and then apply for and install the certificate:
curl https://get.acme.sh | sh; apt install socat -y || yum install socat -y; ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
~/.acme.sh/acme.sh --issue -d mail.xxu.do --standalone -k ec-256 --force --insecure
~/.acme.sh/acme.sh --issue -d mail.xxu.do --webroot /var/www/html
~/.acme.sh/acme.sh --installcert -d mail.xxu.do --key-file /etc/ssl/private/iRedMail.key --fullchain-file /etc/ssl/certs/iRedMail.crt
service postfix reload;service dovecot reload;service nginx reload # Reload services
- Disable iRedMail graylisting (not sure what impact it has, do it according to the tutorial)
vi /opt/iredapd/settings.py
# Remove "greylisting", be sure to maintain the format; or delete the whole line and replace it with the following line
plugins = ["reject_null_sender", "wblist_rdns", "reject_sender_login_mismatch", "greylisting", "throttle", "amavisd_wblist", "sql_alias_access_policy"]
- Set up PTR reverse resolution: Go to your VPS management backend, set the PTR record to the mail server domain name, in this article it is mail.xxu.do, use "
nslookup x.x.x.x
" (server IP) to query. - Set up records:
vi /root/iRedMail-1.6.8/iRedMail.tips
# Find the part similar to the figure below, copy it out, delete all quotes and spaces, and connect them together at the beginning and end.
Get the code like the one below, and fill it into the Content of dkim._domainkey:
v=DKIM1;p=MIIBIjANBgkqhkiG9w0BAQEFAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX