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. 1.SMTP server unreachable
  2. 2.Authentication failure
  3. 3.SSL/TLS misconfiguration
  4. 4.Firewall blocking port 25/587
  5. 5.DKIM/SPF issues

Step 1: Test SMTP Connection

bash
telnet smtp.example.com 587
nc -zv smtp.example.com 587
openssl s_client -connect smtp.example.com:587 -starttls smtp

Step 2: Check SMTP Logs

bash
tail -f /var/log/mail.log
journalctl -u postfix -f
journalctl -u sendmail -f

Step 3: Check Firewall

bash
iptables -L -n | grep -E '25|587|465'
firewall-cmd --list-ports
ufw status

Step 4: Test Authentication

bash
# With telnet:
EHLO localhost
AUTH LOGIN
# Base64 username and password

Step 5: Check SSL Certificate

bash
openssl s_client -connect smtp.example.com:465
echo | openssl s_client -connect smtp.example.com:465 2>/dev/null | openssl x509 -noout -dates

Step 6: Check DNS Records

bash
dig MX example.com
dig TXT example.com | grep SPF
dig TXT _dmarc.example.com

Step 7: Check Postfix Config

bash
postconf -n
cat /etc/postfix/main.cf
postfix check

Step 8: Check Queue

bash
mailq
postqueue -p
postqueue -f

Step 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