Prerequisites
Before setting up Postfix, make sure you have:
- SSH access to your VPS
- Root or sudo privileges
- A registered domain (for full email hosting)
Step 1: Install Postfix
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22
sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt install -y postfix mailutils
When prompted, select:
- Internet Site
- System mail name: your domain or server hostname
Step 2: Configure Postfix for Send-Only (No Incoming)
sudo nano /etc/postfix/main.cf
Ensure these settings:
inet_interfaces = localhost
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost
relayhost =
Restart Postfix:
sudo systemctl restart postfix
Step 3: Test Email Sending
echo "Test email" | mail -s "Postfix Test" your-email@example.com
Step 4: Configure to Use External SMTP Relay (Optional)
To avoid spam filters, relay through a service like SendGrid, AWS SES, or Mailgun.
sudo nano /etc/postfix/main.cf
Add:
relayhost = [smtp.sendgrid.net]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
Create credentials file:
echo "[smtp.sendgrid.net]:587 apikey:YOUR_API_KEY" | sudo tee /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
Restart Postfix:
sudo systemctl restart postfix
Step 5: Set Up Email Forwarding for Root
sudo nano /etc/aliases
Add line:
root: your-email@example.com
Apply:
sudo newaliases
Step 6: Check Mail Log
sudo tail -f /var/log/mail.log
✅ Postfix configured. Your server can now send emails (e.g., cron reports, alerts).