How to test your WordPress mail server with Swaks

Swaks shell command

Introduction

A fully functional email system is an essential aspect of any website, and encountering difficulties when sending emails from your WordPress site can be incredibly disheartening. Even after performing preliminary tests, you may still face challenges in determining the underlying cause of the problem. In such cases, it becomes crucial to separate the various components involved in the email process in order to accurately identify and address the issue.

This article focuses on using Swaks, a versatile “Swiss army knife for SMTP”, to isolate and scrutinize the output generated by the email server you use for WordPress, effectively removing the contact form and mailer plugin elements from the equation.

GitHub – jetmore/swaks: Swaks – Swiss Army Knife for SMTP
Swaks – Swiss Army Knife for SMTP. Contribute to jetmore/swaks development by creating an account on GitHub.
github.com

By doing this, you can obtain valuable insights into the email delivery process, isolate problems, and ultimately enhance your site’s email functionality. We will guide you through using Swaks as a stand-alone tool and a stand-in for WordPress as the email initiator, testing email functionality, and interpreting the results for efficient troubleshooting.

Assumptions

For the purposes of this walkthrough we’ll assume:

Have a WordPress email problem right now? Ask us about it.

We’ll attempt to publish a solution ASAP for free. Challenge us!

So we can notify you when we publish a solution

  1. You have an understanding of the moving parts that enable your WordPress site to send emails – the email-initiating parts (WordPress core, a contact form, or other plugin), the mailer plugin, and the email server/service.
  2. Your mail server uses the SMTP protocol to accept messages from your WordPress site, and not a custom API-based connection, such as is offered by Mailgun and others.
  3. You’re comfortable with the Linux command line.

What is Swaks?

Swaks, or the “Swiss Army Knife for SMTP,” is a versatile and powerful command-line tool designed for testing, debugging, and monitoring SMTP servers. It is highly flexible and customizable, enabling users to perform a wide range of tests to ensure their email servers are functioning correctly.

Features

Some of the key features of Swaks include:

  1. Support for various authentication methods, such as LOGIN, PLAIN, CRAM-MD5, and DIGEST-MD5.
  2. Ability to test email delivery by sending test emails to specified recipients.
  3. Customizable email headers, body, and attachments for more accurate testing.
  4. Support for SSL and TLS encryption to ensure secure communication with the email server.
  5. Detailed reporting of SMTP transaction logs, including timestamps and error messages, for in-depth analysis.
  6. Lightweight and portable.

Prerequisites

Before diving into the process of testing your WordPress email server using Swaks, it’s essential to ensure you have the required software and tools, as well as a basic understanding of email servers and the command-line interface.

  1. Access to the email server: You must have access to the email server you plan to test, including the necessary credentials (username, password) and server information (hostname, port, encryption type). This information is typically available through your hosting provider or email service provider.
  2. Swaks installation: Follow the installation instructions for your operating system here.
  3. WordPress server access and email server details, as set on WordPress: Although a working WordPress installation is not strictly necessary for these tests, you do need to be aware of the details of the email server your site uses to send emails through. Additionally, it is crucial to have access to the command line on the server where WordPress is installed. We recommend installing Swaks on the same server to ensure an accurate representation of the server’s connectivity and email functionality.

Testing Your WordPress Email Server with Swaks

Once you’ve met the prerequisites, you can begin testing your email server using Swaks.

Basic syntax of Swaks command

Documentation of Swaks commands can be found at the following link:

swaks/base.pod at v20201014.0 · jetmore/swaks · GitHub
Swaks – Swiss Army Knife for SMTP. Contribute to jetmore/swaks development by creating an account on GitHub.
github.com

The basic syntax for a Swaks command is as follows:

swaks [options]

Options are used to specify various parameters for your test, such as the recipient, sender, email server, authentication method, and encryption type.

For example:

swaks --to [email protected] --from [email protected] --server smtp.example.com --port 587 --auth LOGIN --user "username" --password "password" --tls
Note

Although you can execute Swaks commands directly from the command line, it’s more convenient to store the commands in a bash script file and run them from there.

Step-by-step guide to testing the email server using a bash script file

1. Create a bash script file

Create a new file named swaks_test.sh in a directory of your choice. This file will contain the Swaks commands for testing your email server.

2. Test the connection to the email server

Add the following Swaks command to swaks_test.sh to test the connection to your email server. Replace smtp.example.com and 587 with your email server’s hostname and port number:

#!/bin/bash

swaks \
--server smtp.example.com \
--port 587

Save the file and make it executable:

chmod +x swaks_test.sh

Run the script from the command line:

./swaks_test.sh

If the connection is successful, you should see a response similar to:

To:

where Swaks is expecting a recipient address. This indicates that Swaks is working correctly. Enter CTRL+C to break out of the program.

3. Test email delivery

Add the following Swaks parameters to swaks_test.sh to test email delivery by sending a test email to a specific recipient. Replace [email protected], [email protected], smtp.example.com, and 587 with the appropriate values for your email server:

#!/bin/bash

swaks \
--to [email protected] \
--from [email protected] \
--server smtp.example.com \
--port 587

Save the file and run the script again:

./swaks_test.sh

The server will likely complain about missing credentials ("530 5.7.1 Authentication required"):

== 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 5242880
<-  250-PIPELINING
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250-DSN
<-  250-AUTH PLAIN LOGIN CRAM-MD5
<-  250 STARTTLS
 -> MAIL FROM:<[email protected]>
<** 530 5.7.1 Authentication required
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.

4. Test authentication and encryption

Add the following Swaks command to swaks_test.sh to test authentication and encryption by including the --auth, --auth-user, --auth-password, and --tls options. Replace the placeholders with your email server’s information:

#!/bin/bash

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

Save the file and run the script again:

./swaks_test.sh

A successful authentication and encryption test will show a response similar to:

=== 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 5242880
<-  250-PIPELINING
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250-DSN
<-  250-AUTH PLAIN LOGIN CRAM-MD5
<-  250 STARTTLS
 -> AUTH CRAM-MD5
<-  334 PDE4NTY1MzM3NDQuMTY4MTI5NTE2NkBzbXRwLmV4YW1wbGUuY29tPg==
 -> cGFzc3dvcmQ=
<-  235 2.0.0 OK
 -> MAIL FROM:<[email protected]>
<-  250 2.1.0 Ok
 -> RCPT TO:<[email protected]>
<-  250 2.1.0 Ok
 -> DATA
<-  354 Go ahead
 -> Date: Wed, 12 Apr 2023 10:26:06 +0000
 -> To: [email protected]
 -> From: [email protected]
 -> Subject: test Wed, 12 Apr 2023 10:26:06 +0000
 -> Message-Id: <[email protected]>
 -> X-Mailer: swaks v20190914.0 jetmore.org/john/code/swaks/
 -> 
 -> This is a test mailing
 -> 
 -> 
 -> .
<-  250 2.0.0 Ok: queued
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.

The response 250 2.0.0 Ok: queued means that the email message has been accepted successfully for delivery.

5. Analyze the results

Carefully review the responses from your server. If the tests are successful, you can be confident that your email server is functioning correctly.

If, however, you encounter any errors or issues, you may need to analyze the SMTP transaction logs, error messages, and connection logs provided by Swaks to identify the cause of any problems. To better understand the SMTP session logs, we recommend reading our companion article How to read an SMTP session log, which provides an introduction to interpreting these logs.

How to read an SMTP session log
Learn how to read an SMTP session log & uncover the secrets of email delivery! Perfect for troubleshooting & understanding WordPress email issues.
nanopo.st

Conclusions from sending mail successfully from Swaks

Successfully sending an email from Swaks to your mail server means the following:

  1. Proper connection: Your WordPress server is capable of connecting to your email server. Your email server’s hostname, port number, and network settings are correct.
  2. Valid authentication: The provided username, password, and authentication method are correct and compatible with your email server’s requirements.
  3. Correct encryption: If SSL/TLS encryption is enabled, your email server’s SSL certificate is valid, and the correct encryption type is used.
  4. Functional email delivery: Your email server can receive and process email messages, suggesting that the server’s core functionality is working as expected.

    However, keep in mind that the mail server might be receiving emails correctly from the client (Swaks in this case, or the WordPress site more generally), but if you’re not receiving these messages into your email, then the server is not relaying the messages on to their destination. Addressing mail server relay issues is beyond the scope of this discussion, and you might consider trying an alternative mail server or seeking assistance from your hosting provider or email service provider to resolve this problem.

If you can successfully receive an email from Swaks through your mail server, any issues you might have with WordPress email are likely in parts other than the email server. Potential problem areas could include the contact form, mailer plugin, or email configurations within WordPress itself.

To continue debugging these components, we recommend reading our article, “How to test WordPress email with Mailtrap”, which provides guidance on identifying and resolving email-related issues within your WordPress site.

How to test WordPress email with Mailtrap
Discover how to debug your WordPress site’s email functionality with Mailtrap. This powerful email testing tool helps identify and resolve email-related issues.
nanopo.st

What if Swaks can’t send any emails?

If Swaks is not capable of sending emails, it may indicate issues with the email server itself rather than WordPress elements, such as the mailer plugin or the contact form. If this test failed, consider the following points:

  1. Connection problems from your WordPress server: The email server’s hostname, port number, or network settings might be incorrect, preventing Swaks from establishing a connection with the server. Double-check these details and ensure there are no network restrictions or firewall settings blocking the connection.

    Be aware that some hosting providers may block port 25 and other SMTP ports as a spam-prevention measure. In such cases, you may need to use an alternative port, configure your email server to use a different port, or contact your hosting provider to request unblocking the required SMTP port.
  2. Authentication errors: The provided username, password, or authentication method might be incorrect or incompatible with your email server’s requirements. Verify the authentication details and ensure they align with your email service provider’s guidelines.
  3. Encryption issues: If SSL/TLS encryption is enabled, there might be problems with your email server’s SSL certificate, port number, or encryption type. Review your email server’s encryption settings to ensure they are configured correctly.
  4. Email server configuration: There could be misconfigurations or errors within the email server settings, which might require further investigation and adjustments to resolve the issue.

If the Swaks test fails, it is essential to focus on troubleshooting the email server, as the root cause of the issue is likely related to its configuration or functionality. Once the email server issues are resolved, and Swaks can successfully send emails, you can have greater confidence that any remaining WordPress email issues are related to other components, such as the contact form or mailer plugin.

Conclusion

By using Swaks to test your email server, you can effectively diagnose and resolve issues related to email delivery and ensure that your WordPress site’s email communication keeps humming.

Leave a Reply

Your email address will not be published. Required fields are marked *