Intro#
To add email subscription and notification to mix-space, I plan to build my own mail server.
After searching online, iRedMail is powerful, easy to use, and not too complicated to deploy. Let's do it!
If you also want to deploy, 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 software:
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 domain, 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 am familiar with nginx, so I 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 domain 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 entire 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 PTR reverse resolution: Go to your VPS management background and set the PTR record to the mail domain, in this article it is mail.xxu.do, use "
nslookup x.x.x.x (server IP)
" to query, - Set records:
vi /root/iRedMail-1.6.8/iRedMail.tips
# Find the part similar to the figure below, copy it out, delete all quotation marks and spaces, and connect the beginning and end together.
Get the code like the following, and fill it into the Content of dkim._domainkey:
v=DKIM1;p=MIIBIjANBgkqhkiG9w0BAQEFAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX