Postfix Smarthost Configuration
Smarthost setup with Postfix main.cf and SASL authentication
Back to DocumentationWhat does this guide do?
Ensures all emails sent from your Postfix server are delivered through the MXGate smarthost (with authentication). Works on Ubuntu, Debian, CentOS, RHEL and other Linux distributions.
Prerequisites
- Root or sudo access
- Postfix installed and running
- SMTP username and password created from MXGate panel
- libsasl2-modules and sasl2-bin packages (usually installed by default)
1 Backup main.cf File
Take a backup of the Postfix configuration file just in case:
2 Configure main.cf
Edit the Postfix main configuration file. Add the following settings to main.cf:
Square brackets [] ensure the hostname is used directly instead of looking up MX records.
3 Create SASL Password File
Create the password file containing SMTP authentication credentials:
Security: This file must not be readable by any user other than root.
4 TLS/SSL Certificate Settings
Set the CA certificates path according to your distribution for TLS encryption:
5 Reload Postfix Configuration
Reload Postfix to apply configuration changes:
6 Testing and Verification
Test if the configuration is working:
Success! All your outgoing emails are now delivered encrypted and authenticated through MXGate.
Troubleshooting
Check username/password:
sudo postmap -q [smtp.mxgate.com.tr]:587 /etc/postfix/sasl_passwd
Re-run postmap command and check file permissions.
Ensure CA certificate file is in correct path. Or disable TLS verification (not recommended):
smtp_tls_security_level = may
Firewall (ufw, firewalld, iptables) may not allow outbound access to port 587. Also ensure your hosting provider doesn't block SMTP ports.
Ensure your server IP is whitelisted in MXGate panel and authentication credentials are correct.
Distribution Specific Notes
Ubuntu/Debian
- main.cf:
/etc/postfix/main.cf - Log:
/var/log/mail.log - CA:
/etc/ssl/certs/ca-certificates.crt
CentOS/RHEL/Rocky
- main.cf:
/etc/postfix/main.cf - Log:
/var/log/maillog - CA:
/etc/pki/tls/certs/ca-bundle.crt