An SMTP test checks whether you can connect to a mail server, upgrade the connection to encryption, sign in and hand over a message. It is the fastest way to find out whether a problem lies in your credentials, your network, your code or the mail server itself. This guide shows how to run an SMTP test from the command line with OpenSSL and Swaks, from PowerShell, from a few lines of Python and with graphical tools, how to read each reply from the server, and how to fix the failures that come up most often.
What does an SMTP test check?
SMTP is a conversation made of short commands and numbered replies. A test walks through that conversation by hand or with a tool, so that you see the exact reply at each step. A full test covers four stages.
- Connection. Your machine opens a network connection to the server's host name and port. A failure here points to DNS, a firewall or a blocked port.
- Greeting and capabilities. The server announces itself, and your client says EHLO. The reply lists what the server supports, such as STARTTLS and AUTH.
- Encryption and authentication. The client upgrades the connection with STARTTLS and signs in. A failure here points to the wrong credentials, the wrong port or a TLS problem.
- Message submission. The client names the sender and recipient and sends the message data. The server answers 250 when it accepts the message.
Acceptance by the server is not delivery to the inbox. A 250 reply at the end means that the server took responsibility for the message. What happens next depends on the destination, as described in how email works.
Before you start: collect the settings
You need the server name, the port, the encryption mode and a username and password. For our relay the server is smtp.migosmtp.com on port 587 with STARTTLS, and the credentials are the SMTP credentials from your account. If you test another provider, copy its values from its documentation. The reasons for each setting are in SMTP settings, ports, TLS and authentication, and port choices are compared in which SMTP port to use.
Test 1: Check that the port is reachable
Start with the simplest check, since many "SMTP failures" are just a blocked port.
# Linux or macOS nc -vz smtp.migosmtp.com 587 # Windows PowerShell Test-NetConnection smtp.migosmtp.com -Port 587
A success message means the network path is open. A timeout means that something between you and the server is blocking the port, which is common on home networks, cloud hosts and corporate firewalls. Our guide to SMTP connection timeouts and TLS errors explains how to track that down.
Test 2: A full SMTP session with OpenSSL
Plain Telnet cannot do STARTTLS, so use OpenSSL, which can open the connection and upgrade it for you.
openssl s_client -starttls smtp -connect smtp.migosmtp.com:587 -crlf -quiet
When the connection is up, the server prints a 220 greeting. Then type the commands below, one line at a time. Your user name and password must be base64 encoded, which you can do beforehand with a command such as printf 'user' | base64.
EHLO test.example.com AUTH LOGIN (paste base64 of the username, press Enter) (paste base64 of the password, press Enter) MAIL FROM:<[email protected]> RCPT TO:<[email protected]> DATA Subject: SMTP test From: [email protected] To: [email protected] This is a test message. . QUIT
The final line before QUIT is a single dot on its own line, which ends the message. Each command should receive a reply that starts with 2 or 3. A reply starting with 4 is a temporary failure. A reply starting with 5 is a permanent failure. Use a throwaway recipient that you control for the test, and never paste real credentials into a shared terminal or a ticket.
Test 3: Swaks, the easiest command-line tool
Swaks (Swiss Army Knife for SMTP) does the whole conversation in one command and shows the exchange, so it is the quickest way to run a repeatable test on Linux or macOS.
swaks --to [email protected] --from [email protected] --server smtp.migosmtp.com --port 587 --tls --auth LOGIN --auth-user YOUR_SMTP_USERNAME --auth-password YOUR_SMTP_PASSWORD
The output shows each line sent and each reply received, which makes it simple to see where the failure happened. Install it from your system's package manager.
Test 4: PowerShell on Windows
PowerShell has a built-in cmdlet called Send-MailMessage, but Microsoft marks it as obsolete because it cannot guarantee a secure connection in every case. For a quick check it still works, and for anything long-lived use a maintained library instead.
$cred = Get-Credential Send-MailMessage -SmtpServer smtp.migosmtp.com -Port 587 -UseSsl ` -Credential $cred -From [email protected] ` -To [email protected] -Subject "SMTP test" -Body "Test"
Test 5: A few lines of Python
Python's standard library has an SMTP client, which makes a handy test from a server that already runs Python, and it exercises the same path your application will take.
import smtplib from email.message import EmailMessage msg = EmailMessage() msg["From"] = "[email protected]" msg["To"] = "[email protected]" msg["Subject"] = "SMTP test" msg.set_content("This is a test message.") with smtplib.SMTP("smtp.migosmtp.com", 587, timeout=20) as s: s.set_debuglevel(1) # prints the full conversation s.starttls() s.login("YOUR_SMTP_USERNAME", "YOUR_SMTP_PASSWORD") s.send_message(msg)
The debug level prints every command and reply, so you can see the exact failure. If you use Node.js, the same exercise is covered in our Nodemailer guide.
Graphical SMTP test tools
If you prefer a window to a terminal, several tools offer a form where you enter the server, port, credentials and message and press send. Free web-based tools are fine for a server that is reachable from the public internet. Be careful with online testers: you hand your credentials to a third party. Use a limited test credential, and rotate it afterwards. For a server on a private network, use a desktop tool or the command-line methods above, since a web tool cannot reach it.
How to read the replies
| Reply | Meaning | What to check |
|---|---|---|
| 220 | Server ready | Connection works |
| 250 | Command accepted | Normal at most steps |
| 235 | Authentication succeeded | Credentials are valid |
| 334 | Server waiting for the next part of the login | Normal during AUTH LOGIN |
| 421 | Service unavailable or too many connections | Retry; check for rate limits |
| 454 or 530 | TLS or authentication needed first | Use STARTTLS and sign in |
| 535 | Authentication failed | Wrong user name or password |
| 550 or 553 | Mailbox or sender rejected | Check the sender and recipient addresses |
| 554 | Transaction failed, often a policy block | Read the text of the reply |
Our guides on SMTP error codes and SMTP bounce codes list many more.
Fixing the most common failures
- Connection timed out. The port is blocked or the host name is wrong. Try another network, and check the firewall.
- Certificate or TLS errors. The system clock may be wrong, the certificate chain may not be trusted on that machine or you may be using the wrong mode on the wrong port.
- 535 authentication failed. Retype the credentials, check for a trailing space or a copied line break and confirm that you use SMTP credentials, not your account login.
- Sender rejected. The From address may not be on a verified domain. See authenticating your sending domain.
- 250 accepted but nothing arrives. Check spam, then the delivery log for a bounce or deferral. Read why emails will not send and tracing a message through the logs.
Testing safely
Use a test recipient that you own, never a list. Keep credentials out of shell history and shared screens, and store them in environment variables. For application development, use a sandbox or a staging setup so that test mail never reaches customers; see test email and staging environments. Limit how often you run tests against a live relay, since repeated failed logins can trigger rate limits.
Ready to send for real? Create SMTP credentials, point your app at the relay on port 587 and watch every message in the logs.
References and further reading
Frequently asked questions
How do I test an SMTP connection?
Check that the port is reachable, open a session with OpenSSL or Swaks using STARTTLS, sign in and submit a test message to an address you own. Read the reply at each step.
Can I use Telnet for an SMTP test?
Plain Telnet works only on connections without encryption, so it cannot do STARTTLS. Use OpenSSL with the starttls smtp option for port 587.
What does 535 mean in an SMTP test?
It means authentication failed. Check the user name and password, and make sure you use SMTP credentials and not your account login.
What does a 250 reply at the end mean?
It means the server accepted the message for delivery. It does not guarantee inbox placement, so check the delivery log if the message does not arrive.
Are online SMTP test tools safe?
They require you to hand credentials to a third party. Use a limited test credential and rotate it afterwards, or use a command-line tool on your own machine.