Use poste.io + nginx proxy manager to build a mail server, with solutions for LE challenge fail
Install poste.io
- First, make sure you have installed docker. If not, you can refer to article
- It is personally recommended to use docker compose for deployment. For the corresponding port introduction, please refer to the official website. If you need to open the anti-virus function (DISABLE_CLAMAV) and the anti-spam function (DISABLE_RSPAMD), you can change the corresponding true to false. However, the memory and CPU usage may increase accordingly.
# docker-compose.yml
services:
mailserver:
image: analogic/poste.io
container_name: mailserver
hostname: mail.yourdomain.com
ports:
- "25:25"
- "110:110"
- "143:143"
- "587:587"
- "993:993"
- "995:995"
- "4190:4190"
- "465:465"
- "8808:80"
- "8843:443"
environment:
- [email protected]
- LETSENCRYPT_HOST=mail.yourdomain.com
- VIRTUAL_HOST=mail.yourdomain.com
- DISABLE_CLAMAV=TRUE
- DISABLE_RSPAMD=TRUE
- HTTPS=OFF
volumes:
- ./mail-data:/data
restart: unless-stopped
- Use
sudo docker compose up -d
to start the mail server - Make sure your domain name
mail.yourdomain.com
is resolved to your server in the DNS resolution. More specifically, select the dns record in your domain name provider, selectA
for type, fill inmail
for name, and fill in your server ip for ipv4 address. - Continue to add records, select
MX
for type, fill inyourdomain.com
for name, and fill inmail.yourdomain.com
for mail server - Add three more CNAME records: names are
smtp
,pop
,imap
, and the target ismail.yourdomain.com
- Add another txt record, name
yourdomain.com
, target"v=spf1 mx ~all"
- Add another txt record, name
_dmarc.yourdomain.com
, target"v=DMARC1; p=none; rua=mailto:[email protected]"
Here[email protected]
can be replaced with any[email protected]
But remember to create the corresponding account in the email server later. - Open your npm. If you have not configured it, please refer to the previous article, add proxy hosts. Fill in
mail.yourdomain.com
for domain names,your IP
for forward hostname/IP, and8808
for forward port. Save. (I have checked all the following 3 options here. In addition, I have also set up an SSL certificate, which allows me to directly open my mail server via https, but there is still a problem with le challenge, so the following solution is still needed) - Open
mail.yourdomain.com
and configure it according to the prompts. Click your virtual domains, and then click Generate dkim key. Open the DNS record of your DNS operator according to the content, add a txt record, fill in the name with the part similar to_s20160910378._domainkey.yourdomain.com
, and write the target with the content similar to"k=rsa;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0FvkMuwN46vvtQCC1JZz7XzRE+l+Lf8/5XUKwWJXOcE7dJoZBbOE0Gz85phZ2q+y4l8D7t/hXDz9q+6/KVQDgJ9muaxSM/uS+KG0ds0QL EiV0GYCVu+ZZQSNPBPjOwlDvo3LraW00lMpd5dUj+xpr07ShfIoULhi7/7t76n5GZMse9yBa4hIhxSG/wCAB4D6IWYBURz9Pc75IDPDTlImr3TP/82YrsULY70CHaPHA1+j1VPA5lE+tnmeqxJW6P537xSutDppv8BZg4nlF3ojg2k6LB/cq15C4QRPAMs77pRA4GVnys1LEJ3JDvV3/csOCZ49oC4m44/TnWXk057OAwIDAQAB"
part - Now everything is configured except ssl is not configured
Solution to LE challenge fail and ssl cannot be configured when using npm
The solution comes from Nginx Proxy Manager Github Issue and official website doc
- First, make sure you have installed docker. If not, you can refer to article
- If you use docker-compose for deployment, you need to add an additional well-known address to the volume. It is best to use the solution mentioned in the github issue, that is, create a docker volume so that both npm and poste io can use it.
# can use this command to creat
sudo docker volume create well-known
After creation, add the following file (if you do not want to call it well-known, make sure to replace well-known with your volume name):
# docker-compose.yml
services:
mailserver:
image: analogic/poste.io
container_name: mailserver
hostname: mail.yourdomain.com
ports:
- "25:25"
- "110:110"
- "143:143"
- "587:587"
- "993:993"
- "995:995"
- "4190:4190"
- "465:465"
- "8808:80"
- "8843:443"
environment:
- [email protected]
- LETSENCRYPT_HOST=mail.yourdomain.com
- VIRTUAL_HOST=mail.yourdomain.com
- DISABLE_CLAMAV=TRUE
- DISABLE_RSPAMD=TRUE
- HTTPS=OFF
volumes:
- ./mail-data:/data
- well-known:/opt/www/.well-known
restart: unless-stopped
volumes:
well-known:
external: true
- Use
sudo docker compose restart
and then go to your mail server and click system settings, click TLS certificate, and click change certificate settings. Check enabled, writemail.yourdomain.com
in common name, andsmtp.yourdomain.com
,pop.yourdomain.com
,imap.yourdomain.com
in alternative names. Click save changes.
Appendix
Here are some recommended testing websites
- MX ToolBox: can check whether dmarc, smtp, etc. are set correctly
- mail tester: test the spammyness of your emails.