sudo apt update && sudo apt upgrade -y
sudo apt install postfix dovecot-core dovecot-imapd mailutils -yEdit the main configuration file:
sudo nano /etc/postfix/main.cfAdd or update these settings:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
inet_interfaces = all
home_mailbox = Maildir/Restart Postfix:
sudo systemctl restart postfixEnable IMAP and Maildir format:
sudo nano /etc/dovecot/conf.d/10-mail.confEnsure this setting is present:
mail_location = maildir:~/MaildirRestart Dovecot:
sudo systemctl restart dovecotInstall Certbot and get a certificate:
sudo apt install certbot -y
sudo certbot certonly --standalone -d mail.yourdomain.comsudo nano /etc/postfix/main.cfAdd:
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.yourdomain.com/privkey.pemsudo nano /etc/dovecot/conf.d/10-ssl.confAdd:
ssl = required
ssl_cert = Restart services:
sudo systemctl restart postfix dovecotAdd a cron job to renew SSL automatically:
sudo crontab -eInsert this line:
0 0 * * * certbot renew --quiet && systemctl reload postfix dovecotConfigure Postfix to use Gmail or another relay:
sudo nano /etc/postfix/main.cfAdd:
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdCreate credentials:
sudo nano /etc/postfix/sasl_passwdAdd:
[smtp.gmail.com]:587 your-email@gmail.com:your-passwordApply changes:
sudo postmap /etc/postfix/sasl_passwd
sudo systemctl restart postfix