Test SMTP from the Command Line

When you need to test from a specific server (because the problem only happens there), these commands show exactly what the mail server says at each step.

7 min read Updated 18 November 2026

1. Check the port is reachable

Linux and macOS:

nc -vz smtp.example.com 587

Windows PowerShell:

Test-NetConnection smtp.example.com -Port 587

If this times out, nothing else will work. The port is blocked between this machine and the server. Compare with the SMTP port checker, which tests from outside your network.

2. Open a session with openssl

Telnet can’t do encryption, and most servers won’t accept a login without it. Use openssl s_client instead.

Port 587 (STARTTLS):

openssl s_client -starttls smtp -connect smtp.example.com:587 -crlf -quiet

Port 465 (SSL/TLS from the start):

openssl s_client -connect smtp.example.com:465 -crlf -quiet

You should see a 220 greeting. Type EHLO test.example.com and the server lists what it supports, including the AUTH methods.

3. Log in with AUTH PLAIN

AUTH PLAIN takes your username and password joined with null characters and base64-encoded. Create the string in a separate terminal:

printf '\[email protected]\0your-app-password' | base64

Then, in the openssl session:

AUTH PLAIN AHlvdUBleGFtcGxlLmNvbQB5b3VyLWFwcC1wYXNzd29yZA==

235 Authentication successful means the login works. 535 means the credentials were rejected. See app passwords.

Careful: base64 is not encryption, and commands with passwords end up in your shell history. Use a test password or clear the history afterwards.

4. Send a message by hand

MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA
Subject: Manual SMTP test
From: [email protected]
To: [email protected]

This message was typed by hand.
.
QUIT

The single dot on its own line ends the message. A 250 reply after it means the server accepted the email.

Faster: swaks

swaks (Swiss Army Knife for SMTP) does all of the above in one command and prints the full conversation. Install it with apt install swaks or brew install swaks.

swaks --to [email protected] --from [email protected] \
  --server smtp.example.com --port 587 --tls \
  --auth LOGIN --auth-user [email protected] --auth-password 'your-app-password'

For port 465, replace --tls with --tls-on-connect.

Also available almost everywhere: curl

Write the message to a file called email.txt:

From: [email protected]
To: [email protected]
Subject: Test from curl

Hello from curl.

Then send it:

curl --url 'smtp://smtp.example.com:587' --ssl-reqd \
  --mail-from [email protected] --mail-rcpt [email protected] \
  --user '[email protected]:your-app-password' \
  --upload-file email.txt -v

For port 465, use smtps://smtp.example.com:465. The -v flag prints the SMTP conversation.

Reading the replies

Codes starting with 2 mean success, 3 means the server is waiting for more input, 4 is a temporary failure and 5 is permanent. Look up any reply in the SMTP error code reference, or skip the terminal and run the online SMTP test, which shows the same transcript with passwords hidden.

Frequently asked questions

Only to check that a port answers and to talk to servers that don’t require encryption (such as port 25 between mail servers). Telnet can’t do STARTTLS or SSL, so you can’t log in to most providers with it. Use openssl s_client instead.

Run openssl s_client -starttls smtp -connect smtp.example.com:587 -crlf -quiet. openssl sends EHLO and STARTTLS for you and shows the certificate, then you can type SMTP commands.

swaks. One command connects, starts TLS, logs in and sends a message, printing every step.