What's Actually Happening

Emails are not being delivered. Outbound emails fail, bounce back, or are marked as spam. SMTP connections fail or timeout.

The Error You'll See

SMTP connection failed:

```bash telnet smtp.example.com 587

Connection refused ```

Authentication error:

bash
535 5.7.8 Username and Password not accepted

Bounce message:

bash
554 5.7.1 Message rejected: Email blocked by spam filter

Why This Happens

  1. 1.SMTP server down - Email server not running
  2. 2.Wrong credentials - Invalid username/password
  3. 3.Port blocked - Firewall blocking SMTP ports
  4. 4.DNS issues - MX record misconfigured
  5. 5.SPF/DKIM failure - Missing authentication records
  6. 6.Rate limited - Sending limit exceeded
  7. 7.Blacklisted - IP address blacklisted

Step 1: Check SMTP Connectivity

```bash # Test SMTP port: nc -zv smtp.example.com 25 nc -zv smtp.example.com 587 nc -zv smtp.example.com 465

# Test with telnet: telnet smtp.example.com 25

# Test with openssl (TLS): openssl s_client -connect smtp.example.com:587 -starttls smtp openssl s_client -connect smtp.example.com:465

# Ping test: ping -c 3 smtp.example.com ```

Step 2: Check Mail Server Status

```bash # Postfix: systemctl status postfix

postfix check

postconf -n

# Sendmail: systemctl status sendmail

# Exim: systemctl status exim

# Check mail queue: mailq postqueue -p

# Flush queue: postqueue -f ```

Step 3: Check Authentication

```bash # Test authentication: telnet smtp.example.com 587 # EHLO localhost # STARTTLS # AUTH LOGIN

# Check SASL: testsaslauthd -u username -p password

# Postfix SASL: cat /etc/postfix/sasl_passwd

postmap /etc/postfix/sasl_passwd

# Check credentials: echo -n "username" | base64 echo -n "password" | base64 ```

Step 4: Check DNS and MX Records

```bash # Check MX records: dig MX example.com

nslookup -type=MX example.com

# Check A record: dig A mail.example.com

# Check reverse DNS: dig -x 1.2.3.4

# SPF record: dig TXT example.com | grep v=spf1

# DKIM: dig TXT selector._domainkey.example.com

# DMARC: dig TXT _dmarc.example.com ```

Step 5: Check Firewall

```bash # Check outbound ports: iptables -L OUTPUT -n | grep -E "25|587|465"

# Allow SMTP: iptables -I OUTPUT -p tcp --dport 25 -j ACCEPT iptables -I OUTPUT -p tcp --dport 587 -j ACCEPT iptables -I OUTPUT -p tcp --dport 465 -j ACCEPT

# UFW: ufw allow out 25/tcp ufw allow out 587/tcp ufw allow out 465/tcp

# Firewalld: firewall-cmd --add-port=587/tcp firewall-cmd --reload ```

Step 6: Check Mail Logs

```bash # Postfix logs: tail -f /var/log/mail.log

journalctl -u postfix -f

# Look for: grep -i "error|fail|reject" /var/log/mail.log | tail -20

# Sendmail logs: tail -f /var/log/maillog

# Check delivery: grep "status=sent" /var/log/mail.log | tail -10 grep "status=bounced" /var/log/mail.log | tail -10 ```

Step 7: Check for Blacklisting

```bash # Check IP reputation: # - https://mxtoolbox.com/blacklists.aspx # - https://www.spamhaus.org/ # - https://www.spamcop.net/

# Check with dig: dig 4.3.2.1.zen.spamhaus.org

# If listed: # 1. Fix the issue (stop spam, secure server) # 2. Request delisting ```

Step 8: Test Email Sending

```bash # Send test email: echo "Test message" | mail -s "Test Subject" user@example.com

# Send with swaks: swaks --to user@example.com --from sender@example.com --server smtp.example.com

# Send with telnet: telnet smtp.example.com 25 HELO localhost MAIL FROM: sender@example.com RCPT TO: user@example.com DATA Subject: Test Test message . QUIT

# Send with curl: curl --url 'smtp://smtp.example.com:587' \ --mail-from 'sender@example.com' \ --mail-rcpt 'user@example.com' \ --upload-file email.txt \ --user 'username:password' ```

Step 9: Check Rate Limits

```bash # Postfix rate limiting: postconf | grep smtp_destination_rate_delay

# Gmail limits: # 500 emails/day for free accounts # 2000 emails/day for G Suite

# AWS SES limits: aws ses get-send-quota

# Check provider documentation for limits ```

Step 10: Monitor Email Delivery

```bash # Monitor mail queue: watch -n 5 'mailq | head -20'

# Check delivery status: tail -f /var/log/mail.log | grep "status="

# Postfix statistics: postfix-stats

# Use monitoring tools: # - Mailchimp reports # - SendGrid dashboard # - AWS SES console ```

Email Not Sending Checklist

CheckCommandExpected
SMTP reachablenc -zv smtpPort open
Mail serversystemctl statusActive
AuthenticationtestsaslauthdSuccess
DNS/MXdig MXRecords correct
SPF/DKIMdig TXTRecords present
Logstail mail.logNo errors

Verify the Fix

```bash nc -zv smtp.example.com 587

systemctl status postfix

echo "Test" | mail -s "Test" user@example.com

tail -f /var/log/mail.log

dig MX example.com

grep "status=sent" /var/log/mail.log | tail -5 ```

  • [Fix Email Going to Spam](/articles/fix-email-going-to-spam)
  • [Fix Email Authentication Failed](/articles/fix-email-authentication-failed)
  • [Fix DNS Resolution Failed](/articles/fix-dns-resolution-failed)