After rebuilding my WordPress server (see Ubuntu 24.04 LTS and WordPress From Scratch), I noticed that I no longer received email notifications about new comments. This was because I neglected to install a mail transfer agent to enable sending emails from the server.
Before enabling the send email function, I want to look at upgrading Ubuntu.
Upgrade to Ubuntu 26.04 LTS
In just half a year, a newer version of Ubuntu 26.04 LTS was released. I thought that I should upgrade my server to the latest Ubuntu version.
Login into the server and do the following to upgrade:
# on the newest versions of packages and their dependencies.
sudo apt update
# Use apt full-upgrade (a.k.a. dist-upgrade), rather than apt upgrade, to
# intelligently handle dependencies and remove obsolete packages.
sudo apt full-upgrade
# Remove dependencies which are no longer used (frees up space)
sudo apt autoremove
# Check for existence of file indicating restart required
[ -f /var/run/reboot-required ] && echo "Reboot required" || echo "No reboot needed"
Reboot required
# If requested, issue a reboot command
sudo reboot
# Check that update-manager-core is installed
apt list --installed | grep "update-manager-core"
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
update-manager-core/noble-updates,now 1:24.04.12 all [installed,automatic]
# If not installed, then install it
sudo apt install upgrade-manager-core
# Upgrade Ubuntu
sudo do-release-upgrade
Checking for a new Ubuntu release
There is no development version of an LTS available.
To upgrade to the latest non-LTS development release
set Prompt=normal in /etc/update-manager/release-upgrades.
The upgrade to 26.04 LTS was not detected and did not occur. The reason is that the do-release-upgrade command delays LTS-to-LTS upgrades until the first point release of the new version (in this case, 26.04.01). So, I’ll need to wait for Ubuntu 26.04.01 LTS to be released before I can upgrade from 24.04.4 LTS.
WordPress Email Basics
By default, WordPress will send an email notification about a new comment. In addition, my WordPress server uses the Comment Reply Email Notification plugin to email the comment authors when I reply to their comments/questions.
WordPress’ ability to send emails depends upon the server having the necessary capability installed, specifically a mail transfer agent. The two common agents are Postfix and Sendmail. Postfix allows the server to send and receive emails, while Sendmail only supports sending.
For an example of how to install and use Postfix, see the “Send Email (using Postfix)” section from Nginx Multiple Domains, Postfix Email, and Mailman Mailing Lists).
The following is an example of how to install Sendmail from my test notes (the notes may be outdated and incomplete):
sudo apt install sendmail
# If your server has a fully qualified domain name (FQDN), update the hosts file
# to fix slow Sendmail startup times or hostname resolution errors.
# Edit /etc/hosts and modify 127.0.0.1 to be:
127.0.0.1 localhost localhost.localdomain myservername myservername.mydomain.com
# Double-check that Sendmail will check the hosts file before DNS.
# The keyword "files" should appear before "dns".
grep hosts /etc/nsswitch.conf
hosts: files dns
# Regenerate the Sendmail configuration (just choose default options)
sudo sendmailconfig
# Restart Sendmail to apply changes
sudo systemctl restart sendmail
# Run PHP interactive shell to test sending an email
php -a
php > $result = mail("testreceiver@somedomain.com", "Test email", "This is a test", "From: root@mydomain.com");
php > echo $result;
php > quit
# If mail takes a long time to arrive, DNS lookup timeout or resolution error may be the cause.
# See above about configuring the FQDN in the hosts file.
Problem Sending Unauthenticated Emails
If you use Postfix or Sendmail to send an email to a Yahoo email address, the email will arrive successfully (last time I checked this was half a year ago). If you send to a Google email address, the email will never be delivered. More than a decade ago, Google started requiring incoming emails to contain critical authentication markers which were DNS records that work together to prove an email sender is real.
The required DNS configuration is very complicated. While I could figure out how to adjust the DNS records for my server, I’m not certain that I can adjust the corresponding domain and hostname resolution because my server exists as a virtual private server.
The simplest solution is to use SMTP (Simple Mail Transfer Protocol) to completely avoid the above. Basically, configure WordPress to log into an existing mail server (for example, Google or Yahoo) to send an email. From the point of view of the recipient, the email originates from Google or Yahoo, which would have the necessary email authentication in place.
Solution is WordPress SMTP Plugin
There are two WordPress plugins, WP Mail SMTP by WPForms and Easy WP SMTP, that provide the SMTP functionality. Because my needs are very basic, I decided to use “Easy WP SMTP”.
Here’s how to install the “Easy WP SMTP” plugin:
- In the WordPress’ Plugins page, click on “Add Plugin”, search for “Easy WP SMTP”, and click on the “Install Now” button.
- Once installed, the button will change to “Activate”. Click on it.
- A configuration wizard will appear. Click “Let’s Get Started”.
- I want to use a Yahoo account, so I select “Other SMTP”. (Yahoo is not listed separately like Google.)
- I input the following Yahoo SMTP configuration:
- SMTP Host: smtp.mail.yahoo.com
- Encryption: TLS
- Port: 587
- Authentication: Enable
- SMTP Username: yourusername@yahoo.com
- SMTP Password: your app password (do not use regular Yahoo account password if two-step verification is enabled; see below for how to create an app password)
- Enable “Force From Name Replacement”, otherwise “WordPress” will be used as the from name.
- Take the defaults for the remaining options. Click on “Save and Continue”.
- I recommend unselecting the optional “Smart Contact Form” and “Weekly Email Summary” because they are unnecessary. Click on “Save and Continue”.
- Click on “Skip this Step” twice.
- Click on “Send a Test Email” or “Finish Setup”. Selecting “Send a Test Email” will finish the setup and take you to “Easy WP SMTP” configuration’s “Send a Test” page.
After finishing setup, the “Easy WP SMTP” plugin will automatically send a test email to the same SMTP account configured.
Here’s how to generate a Yahoo app password if you need one:
- Log into Yahoo Mail.
- Click on top-right user icon and select “Manage your account”.
- Click on the Security tab to the left.
- Scroll down to the “External connections” section.
- Click on “Create app password” to the right.
- Input an App name like “WordPress” and click “Generate password”.
- Copy the generated “one-time app password”. This is what you would input into the “SMTP Password” field above.
Double-check and Reboot
I recommend installing the Check & Log Email plugin. After activation, go to the “Check & Log Email” section under the WordPress administration page and select “Test Email” to send a test email to double-check.
The “Check & Log Email” plugin also provides an “Email Logs” page which records all the emails sent and whether they were sent successfully or not. This feature is very useful when debugging and testing the send email function. (The “Easy WP SMTP” has an “Email Log” page which requires upgrading to the paid PRO license.)
Finally, I suggest rebooting the WordPress server. When I added a test comment, WordPress failed to send the new comment moderation email. The error didn’t say specifically what was the issue. After rebooting the WordPress server and retesting, the new comment moderation email was sent successfully.
