To setup postfix dovecot dkim dmarc spf correctly you will need to follow few steps. Today one of the most popular method to set up an email server is to using postfix. But here are few things you have to do it right to avoid your emails going to spam or get your VPS IP in blacklist:
1) add to your vps ip RDNS
2.1) Add a DNS record for your email server. This can either be an A record pointing to your server’s IP address or a CNAME record pointing to a domain name. Whichever record is chosen, set the hostname/name to mail.
2.2) Add an MX record. Set the hostname/name to @, the mail server to mail.example.com (replacing example.com with your domain name), and the priority to 10. Example :
@ | MX | 10 | mail.example.com |
A | 192.0.2.0 |
2.3) Add a TXT records for SPF and DMARC and DKIM
Example:
@ | 14400 | TXT | v=spf1 a mx ip4:192.0.2.0 ~all |
_dmarc | 14400 | TXT | v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com.; ruf=mailto:dmarc@example.com. |
mail._domainkey | 14400 | TXT | v=DKIM1; k=rsa; t=y; p=MIIBIjANBglqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArJtpYWSD/wX1yiud4jYfeKFOgjtoPeZSkgOiwc92WRvqz2F6NJqR1ELAcJcZD5DCCGjiqPSpKEHwf3LzQxDLBVadXQagyUVtrZKa/nsDO5DohCqvMiN7vt+ba64YfVcGnJx2trH0j86zz8SAKcIwuDezRQJAfCYJzQ/jQpeRHrXZIz5KlePgr/1ls1jqgkDCZoKBEBxlHY6qE7jtBbfBn8/3eo9rpaf2cv2KGdo6N97eiY/y/sGacm8HKT6FH5/ORrWOGO19jAyO7ks2mjN9GPJzIi/bjJ7F2nhr/XkDwkpvB0qwLKZ/xAV2Gr1YnJW2LvZm9Q05udc5ahRWegYYbwIDAQAB |
1) Install all the apps in red
if you manage your DNS for your Domain than you can skip install Bind9.
if You only want to install the mail server than Skip NGINX and Mailutils
if you want to a protect your postfix than recomend to install fail2ban and iptables-persistent
2) Swith on your firewall and allow access to the next ports (25, 465, 587, 110, 995, 143, and 993)
3) Install SSL
3.1 If you manage your DNS records on your VPS than you need to install NGINX and add new domain
For point - 2
3.2) if you manage your DNS for the domain outside of your vps than skip 3.1 you can install the SSL from here, first make sure you have all ready seted the A records for www.example.com and example.com
@ | A | 192.0.2.0 |
www | A | 192.0.2.0 |
A | 192.0.2.0 |
4) Configure the Postfix-Dovecot-Dkim-Dmarc-Spf
5) Add a TXT DNS dkim record, You can get DKIM key for TXT record by folow next steps:
6) Test your DNS sould be all Green, if you manage your dns outside of your vps, than may take a while untill your DNS will be updated, if you manage your DNS on your vps just restart bind9