WordPress email problems have three moving parts: the plugin that triggers the email, the mailer plugin that routes it, and the SMTP server that sends it. When mail breaks, the fastest way to find the fault is to remove the first two and talk to the SMTP server directly.
Swaks (Swiss Army Knife SMTP) does exactly that. It is a single-file Perl script that opens an SMTP session from the command line, testing connectivity, authentication, TLS, and delivery without WordPress or PHP in the loop. The script lives at
jetmore.org with a mirror on
GitHub.
This guide covers the diagnostic side. For the initial WordPress email configuration that swaks is used to verify, see How to set up email on WordPress.
Before you start
This walkthrough assumes:
- The mail server accepts messages over SMTP, not a provider-specific API (Mailgun HTTP API, Amazon SES API, etc.). API-based connections bypass SMTP entirely and cannot be tested with Swaks.
- You have SSH access to the server where WordPress runs and are comfortable with the Linux command line.
What is Swaks?
Swaks opens an SMTP session from the command line, runs through the SMTP transaction (EHLO, AUTH, MAIL FROM, RCPT TO, DATA), and prints every line of the exchange. That transcript is the diagnostic: it shows exactly where the conversation succeeds or fails.
Relevant capabilities for WordPress SMTP testing:
- Authentication methods: LOGIN, PLAIN, CRAM-MD5, DIGEST-MD5 (covers every method WordPress mailer plugins use).
- STARTTLS and implicit TLS.
- Custom headers, body, and attachments.
- Full SMTP transaction log with server response codes.
The -v and --verbose flags in swaks
Swaks has no -v or --verbose flag. The full SMTP transcript, showing every -> line sent and every <- line received, is the default output; you do not turn it on. What you turn on is the reverse: --silent (short form -S) suppresses the transcript.
-S 1(or--silent 1) prints nothing on success and prints the full transcript on error.-S 2prints only errors.-S 3prints nothing at all, even on error.
If a guide or a Stack Overflow answer tells you to add -v to swaks for a verbose SMTP session, the guide is confusing swaks with another SMTP client (smtp-cli, openssl s_client, curl --mail-*). The swaks equivalent is: run the command as written and read the transcript it prints.
Prerequisites
- SMTP credentials: hostname, port, encryption type, username, and password for the mail server your WordPress site sends through. If your mailer plugin connects over SMTP with a password (WP Mail SMTP, FluentSMTP, and Post SMTP all can), these are the values in its SMTP settings. A plugin connected by OAuth has no SMTP password to copy; Gmail SMTP works only that way, storing a Google client ID, client secret, and token.
- Swaks installed on the WordPress server: install from the
official instructions or your distribution’s package manager (apt install swaks,dnf install swaks). Install on the same server as WordPress; this ensures the test reflects the same network path, firewall rules, and DNS resolution that WordPress uses.
Testing WordPress SMTP with Swaks
Each step isolates one variable: connection, then authentication, then a full send. A complete Swaks command looks like this:
swaks --to [email protected] --from [email protected] --server smtp.example.com --port 587 --auth LOGIN --auth-user "username" --auth-password --tls --tls-verify
The full option reference is in the
Swaks base documentation.
Step 1: Test the connection
Save the following as swaks_test.sh:
#!/bin/bash
swaks \
--server smtp.example.com \
--port 587 \
--quit-after CONNECT
Replace smtp.example.com and 587 with your SMTP server’s hostname and port. If the port is 465, add --tlsc. Then make it executable and run it:
chmod +x swaks_test.sh
./swaks_test.sh
If the connection succeeds, Swaks prints === Connected to smtp.example.com. and the server’s 220 greeting, then quits. --quit-after CONNECT makes this a connection test. Without it, and without --to, Swaks asks for a recipient at a To: prompt before it opens any connection.
If it fails here, the problem is network-level: wrong hostname, wrong port, firewall blocking the connection, or the hosting provider blocking outbound SMTP.
Bluehost’s shared IP addresses, for example, allow outbound connections only on ports 80 and 443. See the troubleshooting section below.
Step 2: Test email delivery
Add sender/recipient addresses to test whether the server accepts a message. Replace the placeholder addresses with real values:
#!/bin/bash
swaks \
--to [email protected] \
--from [email protected] \
--server smtp.example.com \
--port 587
The server will reject the message with 530 5.7.1 Authentication required. This is expected. The point of this step is to confirm that the SMTP session reaches the MAIL FROM stage, proving that the connection and EHLO handshake work:
=== Trying smtp.example.com:587...
=== Connected to smtp.example.com.
<- 220 smtp.example.com ESMTP ready
-> EHLO yourserver.hosting.com
<- 250-smtp.example.com
<- 250-SIZE 33554432
<- 250-8BITMIME
<- 250-STARTTLS
<- 250-AUTH LOGIN PLAIN
<- 250 HELP
-> MAIL FROM:<[email protected]>
<** 530 5.7.1 Authentication required
-> QUIT
<- 221 Bye
=== Connection closed with remote host.
The -> lines are what Swaks sent; the <- lines are server responses; <** marks a server-side rejection (the three-digit SMTP status code on that line is what to read first). Note the 250-AUTH LOGIN PLAIN line in the EHLO response: it lists the authentication methods the server supports. Match the --auth flag in the next step to one of these. In our test on 2026-11-25 with Swaks 20240103.0, smtp.gmail.com listed AUTH in the second EHLO response, after STARTTLS. Server responses can change. If the AUTH line is missing, add --tls and look again.
Step 3: Test authentication and TLS
Add authentication and TLS. Use the same credentials configured in your WordPress mailer plugin:
#!/bin/bash
swaks \
--to [email protected] \
--from [email protected] \
--server smtp.example.com \
--port 587 \
--auth LOGIN \
--auth-user "username" \
--auth-password \
--tls \
--tls-verify
--tls-verify makes Swaks stop if the server’s certificate fails verification. By default Swaks does not require a valid certificate.
--auth-password with no value makes Swaks look for the password in .netrc and prompt if it cannot find one. The prompt normally shows the password as you type. Add --protect-prompt and Swaks tries to mask the input, though that can fail on some terminals.
A password written after --auth-password is visible in ps output while Swaks runs, and in shell history if you typed the command. chmod 700 on the script does not change what ps shows, and neither does --auth-password $(cat ~/.swaks-pass): the shell expands it before Swaks starts, and in testing the password was in the ps line.
For runs with no prompt, put the credentials in .netrc in the home directory of the user that runs Swaks:
machine smtp.example.com
login username
password your-password
Set it to mode 600 (chmod 600 ~/.netrc); Swaks ignores a file that its group or other users can access, and prompts instead. The machine name must match --server. Keep --auth LOGIN and leave out --auth-user and --auth-password.
The transcript prints the username and password in base64, which anyone can decode. Add --auth-hide-password before you share the output; it replaces the password but not the username.
A successful authentication and delivery produces 250 2.0.0 Ok: queued:
=== Trying smtp.example.com:587...
=== Connected to smtp.example.com.
<- 220 smtp.example.com ESMTP ready
-> EHLO yourserver.hosting.com
<- 250-smtp.example.com
<- 250-SIZE 33554432
<- 250-8BITMIME
<- 250-STARTTLS
<- 250-AUTH LOGIN PLAIN
<- 250 HELP
-> STARTTLS
<- 220 Ready to start TLS
=== TLS started with cipher TLSv1.3:TLS_AES_256_GCM_SHA384:256
=== TLS client certificate not requested and not sent
=== TLS no client certificate set
=== TLS peer[0] subject=[/CN=smtp.example.com]
=== commonName=[smtp.example.com], subjectAltName=[DNS:smtp.example.com] notAfter=[2027-01-14T09:03:12Z]
=== TLS peer certificate passed CA verification, passed host verification (using host smtp.example.com to verify)
~> EHLO yourserver.hosting.com
<~ 250-smtp.example.com
<~ 250-SIZE 33554432
<~ 250-8BITMIME
<~ 250-AUTH LOGIN PLAIN
<~ 250 HELP
~> AUTH LOGIN
<~ 334 VXNlciBOYW1lAA==
~> dXNlcm5hbWU=
<~ 334 UGFzc3dvcmQA
~> cGFzc3dvcmQ=
<~ 235 2.7.0 Authentication successful
~> MAIL FROM:<[email protected]>
<~ 250 2.1.0 Ok
~> RCPT TO:<[email protected]>
<~ 250 2.1.0 Ok
~> DATA
<~ 354 End data with <CR><LF>.<CR><LF>
~> Date: Wed, 25 Nov 2026 09:03:54 +0000
~> To: [email protected]
~> From: [email protected]
~> Subject: test Wed, 25 Nov 2026 09:03:54 +0000
~> Message-Id: <[email protected]>
~> X-Mailer: swaks v20240103.0 jetmore.org/john/code/swaks/
~>
~> This is a test mailing
~>
~>
~> .
<~ 250 2.0.0 Ok: queued
~> QUIT
<~ 221 Bye
=== Connection closed with remote host.
Once TLS starts, the arrows change to ~> and <~. This transcript was captured on 2026-11-25 with Swaks 20240103.0 against a local test server. The capture used a test CA trusted through SSL_CERT_FILE, --tls-verify-target smtp.example.com, and a literal test password rather than a real account password. The displayed hostname, port, and Message-Id host were substituted, and the password prompt is omitted. The prompt form shown in Step 3 was tested separately. The Step 2 transcript was captured the same day against the same test server, with the hostname and port substituted.
The 250 2.0.0 Ok: queued response confirms the mail server accepted the message for delivery. Check the recipient inbox (including spam/junk) to verify end-to-end delivery. For a full walkthrough of SMTP response codes and session structure, see How to read an SMTP session log.
What a successful Swaks test proves
A 250 Ok: queued response from Swaks confirms four things:
- Network path: the WordPress server can reach the SMTP server on the configured hostname and port. No firewall, DNS, or routing issues.
- Authentication: the username, password, and auth method are accepted.
- TLS: if
--tlsor--tlscwas used, the encryption negotiation succeeded. This confirms the certificate only if--tls-verifywas used as well. Without it, Swaks 20240103.0 queued a message through a server with an expired certificate, one with a self-signed certificate, and one with a certificate for another hostname, and said so only in theTLS peer certificateline. In Swaks 20201014.0,--tls-verifyrejected the expired certificate but accepted the wrong hostname, so checkswaks --version. - Server accepts mail: the SMTP server queued the message for delivery.
One thing it does not prove: that the message reaches the recipient’s inbox. The SMTP server accepted the message, but it may still be rejected downstream (spam filters, relay configuration, DNS-based reputation checks). If Swaks succeeds but mail never arrives, the failure is on the mail server’s outbound relay or the recipient’s inbound filtering – both sit outside what this test can see.
If Swaks succeeds and mail arrives, the SMTP layer is clean. Any remaining WordPress email problems are in the plugin stack: the mailer plugin configuration, the contact form, or wp_mail() itself.
For testing the WordPress side of the chain (once you have confirmed the SMTP server works), see How to test WordPress email with Mailtrap.
Troubleshooting: when Swaks fails
If Swaks cannot complete the SMTP transaction, the fault is between the WordPress server and the mail server, not in WordPress itself. Common failure points:
| Symptom | Likely cause | Fix |
|---|---|---|
| Connection timeout / “Network is unreachable” | Wrong hostname or port; firewall blocking outbound SMTP | Verify hostname and port. If the host blocks port 25, as |
530 Authentication required or 535 Authentication failed |
Wrong username, password, or auth method | Double-check credentials. Match --auth to a method listed in the server’s EHLO response. |
*** TLS startup failed with wrong version number |
--tlsc used on a STARTTLS port |
Port 587 typically uses STARTTLS: use --tls. |
=== Connected, then no 220 greeting, ending in Timeout (30 secs) waiting for server response or Remote host closed connection unexpectedly |
--tls, or no TLS flag, used on an implicit TLS port |
Port 465 uses implicit TLS: use --tlsc. |
*** TLS startup failed with certificate verification failed or server certificate did not match target host (only with --tls-verify) |
Expired or self-signed certificate, or a certificate for another hostname | Use the hostname your provider gives for SMTP. If that is already the hostname, whoever runs the server has to fix the certificate. |
550 Relay denied or 553 Sender address rejected |
The --from address is not authorised on this server |
Use the exact sender address configured in the provider’s dashboard. |
If the Swaks test fails, the mail server (or the network path to it) is the problem. Fix it at that layer before returning to debug WordPress plugins.
Corrections
- 2026-11-26: an earlier version said many shared hosts block port 25, with no source covering them. The table now names hosts that document a block: WP Engine blocks port 25, and DigitalOcean blocks 25, 465 and 587 on Droplets.
- 2026-11-26: an earlier version said, with no source, that blocking outbound SMTP is common on shared hosts. The step now names a host that documents a block.
- 2026-11-25: an earlier version listed Gmail SMTP among plugins that hold an SMTP hostname, username, and password. It stores Google OAuth credentials and a token, and no SMTP password.
- 2026-11-25: an earlier version said a successful run with
--tlsproves the server’s certificate is valid, and listed an expired certificate as a cause of TLS handshake failure. Swaks does not require a valid certificate unless--tls-verifyor a related option is used. - 2026-11-25: an earlier version recommended
--auth-password $(cat ~/.swaks-pass)andchmod 700on the script as ways to protect the password. Neither keeps it out ofpsoutput. - 2026-11-25: an earlier version said mixing up ports 587 and 465 fails silently. Swaks reports a TLS error in one direction and a timeout or closed connection in the other.
- 2026-11-25: an earlier version of step 1 read the
To:prompt as proof of a connection. Swaks shows that prompt before it connects. - 2026-11-25: an earlier transcript showed a CRAM-MD5 login under a command that used LOGIN and
--tls.

