cheat-sheets

SMTP

Simple Mail Transfer Protocol moves email between servers and from clients to servers. Related: Mail Server DNS Records Cheat-Sheet, Generate a DKIM Keypair, TLS (Transport Layer Security).

Ports #

PORTUSE
25Server to server delivery (often blocked for clients by ISPs)
587Mail submission with STARTTLS (preferred for clients)
465Submission with implicit TLS
2525Unofficial alternative submission port some providers offer

Quick Tests #

COMMANDDESCRIPTION
nc -zv smtp.example.com 587Is the port open?
dig +short MX example.comMail servers for a domain
dig +short TXT example.comSPF record
dig +short TXT _dmarc.example.comDMARC policy
swaks --to <TO> --from <FROM> --server smtp.example.com:587 --tls --auth LOGIN --auth-user <USER>Send a test mail with swaks
openssl s_client -starttls smtp -connect smtp.example.com:587Manual STARTTLS session

Troubleshooting #

TLS #

  1. Prepare encoded strings for your mail username and password
bash
echo -ne "mail@example.net" | base64
echo -ne "password" | base64
  1. Connect to mail server
bash
openssl s_client -starttls smtp -connect smtp.example.com:587

For port 465 use openssl s_client -connect smtp.example.com:465.

  1. Send HELO
smtp
EHLO example.com
  1. Authenticate
smtp
AUTH LOGIN
<your-encoded-username>
<your-encoded-password>

If that’s successful the mail server should return 235 2.7.0 Authentication successful.

  1. Send a test message
smtp
MAIL FROM:<from@example.com>
RCPT TO:<to@example.net>
DATA
Subject: test

Hello
.
QUIT

Common Reply Codes #

CODEMEANING
220Service ready
235Authentication successful
250OK
354Start mail input, end with . on its own line
421Service unavailable, try later
450 / 451Temporary mailbox or local error (greylisting)
535Authentication failed
550Mailbox unavailable or rejected (policy, SPF, blocklist)
554Transaction failed

Check Mail Queue (Postfix) #

COMMANDDESCRIPTION
postqueue -pShow the queue
postqueue -fFlush the queue
postsuper -d ALL deferredDelete deferred mail
tail -f /var/log/mail.logFollow the mail log
Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.