To test an SMTP server you need three checks, in this order: can you reach the port, does TLS work, and will the server accept an authenticated message. Use telnet or nc for the first, openssl s_client for the second, and swaks for the third. Each one isolates a different layer, so a failure tells you whether to look at the network, the certificate or the credentials.
The commands below use mail.example.com, example.com addresses and a placeholder password. Replace them with your own values and only test servers you operate or are authorised to use. Do not paste real passwords into shared terminals or shell history.
Before you start
- Find the right host and port. Submission uses 587 with STARTTLS or 465 with implicit TLS; server to server mail uses 25. See which port to use.
- Many residential and cloud networks block outbound port 25, so a test on 25 can fail for reasons unrelated to the server.
- For a destination domain, find its mail servers with
dig +short MX example.org. - Have a test credential and a mailbox you control for the recipient.
dig +short MX example.org
nslookup -type=MX example.orgInstalling the tools
Most Linux distributions package all three tools. Package names vary slightly between distributions, so check your package manager if a name is not found.
# Debian and Ubuntu
sudo apt install swaks openssl netcat-openbsd telnet
# RHEL, Fedora and derivatives
sudo dnf install swaks openssl nmap-ncat telnet
# macOS with Homebrew
brew install swaks opensslWindows does not ship telnet enabled by default, which is one reason Test-NetConnection is the easier port check there. For TLS and message tests on Windows, use WSL or a native build of OpenSSL and Swaks.
Step 1: test the port with telnet or nc
A successful TCP connection and a 220 banner prove that the host, DNS, routing and firewall allow SMTP. Connect, read the banner, then leave with QUIT.
telnet mail.example.com 587
Trying 203.0.113.25...
Connected to mail.example.com.
220 mail.example.com ESMTP
EHLO test.example.net
250-mail.example.com
250-STARTTLS
250-AUTH PLAIN LOGIN
250 SIZE 52428800
QUIT
221 2.0.0 ByeIf telnet is not installed, nc gives the same reachability check without a session, and PowerShell has a built-in equivalent.
nc -vz mail.example.com 587
# Windows PowerShell
Test-NetConnection -ComputerName mail.example.com -Port 587Port 465 will not show a readable banner in telnet, because the server expects a TLS handshake first. Use openssl for that port. If the connection hangs or is refused, see connection timed out and refused errors and SMTP firewalls.
Step 2: test TLS with openssl s_client
openssl s_client performs the TLS handshake and prints the certificate chain, protocol version and verification result. For STARTTLS ports (25 and 587) add -starttls smtp. For implicit TLS on 465, connect directly. The -crlf option sends the correct line endings when you type commands.
# STARTTLS on 587
openssl s_client -starttls smtp -crlf -connect mail.example.com:587 -servername mail.example.com
# Implicit TLS on 465
openssl s_client -crlf -connect mail.example.com:465 -servername mail.example.comAfter the handshake you are inside an encrypted session and can type SMTP commands by hand. Look at three things in the output: the Verify return code (0 means the chain verified), the certificate subject and alternative names (they must include the hostname you connect to), and the expiry date. If you want the server to fail on a bad chain, add -verify_return_error.
EHLO test.example.net
250-mail.example.com
250-AUTH PLAIN LOGIN
250 SIZE 52428800
QUITCertificate problems are covered in SMTP certificate errors and connection timeout and TLS errors. Note that the AUTH line often appears only after TLS is active, so run EHLO again inside the session.
Step 3: send a full test message with swaks
Swaks (Swiss Army Knife for SMTP) is a scriptable test tool, available from most package managers. It runs the whole conversation, optionally with TLS and authentication, and prints every line exchanged, which makes it the most useful of the three. Enter the password through an environment variable or prompt rather than the command line when you can, since arguments are visible in the process list.
# STARTTLS on 587 with authentication
swaks --to [email protected] --from [email protected] \
--server mail.example.com --port 587 --tls \
--auth LOGIN --auth-user [email protected] --auth-password 'REPLACE_ME'
# Implicit TLS on 465
swaks --to [email protected] --from [email protected] \
--server mail.example.com --port 465 --tls-on-connect \
--auth PLAIN --auth-user [email protected] --auth-password 'REPLACE_ME'
# Stop after the recipient is accepted, without sending a message
swaks --to [email protected] --from [email protected] \
--server mail.example.com --quit-after RCPTLines starting with -> are what swaks sent and lines starting with <- are the server replies. A normal run ends with a 250 after the data and a 221 after QUIT. You can add --header "Subject: Test" and --body "Hello" to control the content, or --ehlo to set the name you present.
Step 4: test deliverability separately
A server can accept your test message and the message can still land in spam. Acceptance with 250 tells you only that the next hop took responsibility. To test the rest, send to a mailbox you control, then read the headers for the Authentication-Results line to confirm SPF, DKIM and DMARC. See reading email headers and checking spam placement. You can also check your domain records with the SPF, DKIM and DMARC checker.
Testing an incoming (MX) server
To test a server that receives mail for a domain, connect to the host from the MX lookup on port 25 and attempt a delivery to a mailbox you own, without authentication. The server should accept mail for its own domains and refuse everything else with a relay denial.
# Should be accepted: recipient in the server's own domain
swaks --to [email protected] --from [email protected] --server mx1.example.org --quit-after RCPT
# Should be refused with a relaying denied reply: recipient in a foreign domain
swaks --to [email protected] --from [email protected] --server mx1.example.org --quit-after RCPTIf the second command is accepted, the server may be an open relay, which is a serious fault that attracts abuse and blocklisting. Fix it before anything else. Also confirm that the name the server announces in its banner matches its reverse DNS, since many receivers check that. See relay access denied for the expected refusal and reverse DNS and HELO names.
Measuring time and checking limits
Slow tests are informative too. Run swaks with --timeout 30 and note where the delay occurs. A long pause before the banner usually points to a reverse DNS lookup on the server side, while a delay after RCPT TO or after the dot points to recipient verification or content scanning. The size limit appears in the SIZE line of the EHLO reply, which you can compare with the size of the message you plan to send. Recipient limits, per-connection message limits and rate limits are not always advertised, so confirm them in the server or provider documentation instead of discovering them in production.
Reading the results
| What you see | What it means | Next step |
|---|---|---|
| Connection refused | Nothing is listening on that port, or a firewall rejects it | Check the port, service status and firewall |
| Connection timed out | Packets are dropped, often by a network blocking outbound 25 | Try 587 or 465, or another network |
| 220 banner then silence on 465 | Server expects TLS first | Use openssl s_client or swaks --tls-on-connect |
| Verify return code not 0 | Untrusted, expired or wrong-name certificate | Fix the certificate or the hostname you connect to |
| 530 5.7.0 Must issue STARTTLS | Authentication before TLS | Add --tls, or use openssl -starttls smtp |
| 535 authentication failed | Wrong credentials | Recheck the username format and password |
| 550 or 554 on RCPT TO or DATA | Recipient or policy rejection | Read the reply text; see SMTP response codes |
| 421 or 450 | Rate limit or temporary deferral | Wait and retry slowly |
Safe testing habits
- Test with your own addresses, never with real customers or third-party mailboxes.
- Keep test volume low. Repeated rapid connections can trigger rate limits or blocklisting.
- Use a staging domain or sandbox for application tests. See staging and sandbox testing.
- Clear shell history or use environment variables after testing with real credentials.
- Never test relaying through a server you do not own. See open relay for why servers are expected to refuse that.
When to use each tool and next steps
Use nc or Test-NetConnection for a quick reachability check, openssl s_client when the symptom is a TLS or certificate error, and swaks for an end to end test including authentication. For a broader walk through of connection tests see testing an SMTP connection, and to understand the lines you are typing, read SMTP commands explained.
Test against a relay built for sending Connect to smtp.migosmtp.com on 587 or 465 and watch each delivery event as it happens.
References and further reading
Frequently asked questions
How do I test an SMTP server with telnet?
Run telnet host 25 or 587, wait for the 220 banner, send EHLO, then QUIT. It checks reachability but cannot test TLS.
How do I test SMTP over TLS with openssl?
Use openssl s_client -starttls smtp -connect host:587 for STARTTLS, or openssl s_client -connect host:465 for implicit TLS. Check the verify return code.
Why can I not use telnet on port 465?
Port 465 uses TLS from the first byte, so the server waits for a handshake that telnet does not perform. Use openssl s_client or swaks with --tls-on-connect.
What is swaks?
Swaks is a command line tool that sends a test message and prints the entire SMTP conversation, with options for TLS, authentication and custom headers.
Does a 250 reply mean the message reached the inbox?
No. It means the receiving server accepted the message for processing. Spam filtering and later bounces can still affect the result.