To test an IMAP connection, open Terminal on a Mac and run openssl s_client -connect with the server and port, such as imap.gmail.com:993. A line that begins * OK means the server answered and the encryption worked; an SMTP server answers with 220. To check only whether a port is open, nc -vz with the server and port says succeeded or times out, and on Windows Test-NetConnection does the same.
Check whether the port is open
The quickest test only asks whether anything answers at the port. Use your own provider's server name in place of Gmail's, and 465 or 587 to check an outgoing port.
| Computer | Command |
|---|---|
| Mac (Terminal) | nc -vz imap.gmail.com 993 |
| Windows (PowerShell) | Test-NetConnection imap.gmail.com -Port 993 |
“succeeded” on a Mac, or TcpTestSucceeded : True on Windows, means the port is open from where you are. No answer means a network on the way is blocking it, or the server name or the port is wrong.
Test IMAP on port 993
This one goes further: it connects with SSL/TLS, as a mail app does, and shows the server's greeting.
| Port and security | Command in Terminal |
|---|---|
| 993, SSL/TLS | openssl s_client -connect imap.gmail.com:993 -crlf |
| 143, STARTTLS | openssl s_client -starttls imap -connect imap.example.com:143 -crlf |
After the certificate's details, the server greets you with a line that begins * OK. That proves the server name is right, the port is open and the encryption works. Type a1 LOGOUT and press Return to leave. Gmail has no port 143, so the second line uses a made-up server name: put in your own. IMAP's ports.
Test SMTP on port 465 or 587
Port 465 is encrypted from the first byte. Port 587 starts in plain text, and -starttls smtp asks the server to switch to encryption, as a mail app does.
| Port and security | Command in Terminal |
|---|---|
| 465, SSL/TLS | openssl s_client -connect smtp.gmail.com:465 -crlf |
| 587, STARTTLS | openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf |
Either way, the server answers with lines that begin 220 or 250. Type QUIT and press Return to leave. SMTP's ports.
What the results mean
- Connection refused: nothing is listening at that port. Check the port number.
- It hangs, then times out: a VPN, a firewall, or an office, school or hotel network is probably blocking the port. Try another network, or the provider's other port.
- The name can't be found: the server name is wrong. Check it against your provider's help pages, letter for letter.
- A certificate or handshake error: the security doesn't match the port (SSL/TLS goes with 993 and 465, STARTTLS with 143 and 587), or the server's certificate isn't one your computer trusts.
- A greeting, but your mail app still can't sign in: the connection is fine, so look at the password. Many providers want an app password in mail apps.
Testing in LocalInbox
LocalInbox checks the servers itself when you add an account, and its message says which of these it met: nothing answering at the port, a secure connection of the wrong kind, a certificate this Mac doesn't trust, a server name it couldn't find, or no answer in time, where it names the port a network may be blocking. Every provider's servers and ports.
Sources
What this page says about the commands comes from OpenSSL's and Microsoft's own pages, and about the servers' greetings from the standards, all linked below. What it says about LocalInbox comes from the app.
Questions
How do I check if port 587 is open?
On a Mac, run nc -vz smtp.gmail.com 587 in Terminal, with your own provider's server name. On Windows, run Test-NetConnection smtp.gmail.com -Port 587 in PowerShell. “succeeded”, or TcpTestSucceeded : True, means it's open from where you are.
Is it safe to test a mail server this way?
Yes. These commands connect and read the server's greeting, nothing more. Don't type your password into the session; signing in is your mail app's job.
Does a successful test mean my settings are right?
It means the server name, the port and the security are right. The user name and the password are only checked when a mail app signs in.
Do I need to install anything?
No. A Mac comes with openssl and nc, and Windows with Test-NetConnection in PowerShell.