What's Actually Happening
Emails are not being sent from applications. SMTP connections fail or emails are rejected by mail servers.
The Error You'll See
```bash $ sendmail -v user@example.com
Connection refused by mail.example.com ```
Why This Happens
- 1.SMTP server unreachable
- 2.Authentication failure
- 3.SSL/TLS misconfiguration
- 4.Firewall blocking port 25/587
- 5.DKIM/SPF issues
Step 1: Test SMTP Connection
telnet smtp.example.com 587
nc -zv smtp.example.com 587
openssl s_client -connect smtp.example.com:587 -starttls smtpStep 2: Check SMTP Logs
tail -f /var/log/mail.log
journalctl -u postfix -f
journalctl -u sendmail -fStep 3: Check Firewall
iptables -L -n | grep -E '25|587|465'
firewall-cmd --list-ports
ufw statusStep 4: Test Authentication
# With telnet:
EHLO localhost
AUTH LOGIN
# Base64 username and passwordStep 5: Check SSL Certificate
openssl s_client -connect smtp.example.com:465
echo | openssl s_client -connect smtp.example.com:465 2>/dev/null | openssl x509 -noout -datesStep 6: Check DNS Records
dig MX example.com
dig TXT example.com | grep SPF
dig TXT _dmarc.example.comStep 7: Check Postfix Config
postconf -n
cat /etc/postfix/main.cf
postfix checkStep 8: Check Queue
mailq
postqueue -p
postqueue -fStep 9: Test Email
```bash echo "Test" | mail -s "Test Subject" user@example.com sendmail -v user@example.com << EOF Subject: Test From: sender@example.com Test message