Emails are an important communication tool, and many times the only communication tool on websites. A majority of website owners assume that emails are being delivered as expected but sadly this is not always the case. Logging your email communication in your WordPress database has several benefits including:
- Know for sure that emails are being sent out to your customers or clients,
- Email notifications can help you debug other features on your website including online orders, form submissions, and user profile features,
- Logging emails helps you detect unauthorized communication or misuse by plugins and other entities. Email logging has been especially useful to detect spam/malware injection where the offending malware uses your system to send out emails
The plugin we'll use for logging emails is the WP Mail SMTP. WP Mail SMTP has many functions including enabling SMTP email settings for better email delivery. If you're not using SMTP to send out emails then I highly recommend you do so using this plugin.
First, head over to your WordPress admin and look for Plugins -> Add New. On the next page that opens up, enter the phrase ‘WP Mail SMTP' on the top right search box and hit enter.
When the search results are presented to you, click on the install button next to the WP Mail SMTP listing then activate it. Now we're ready to customize the plugin.
Email Log Settings
Now that the WP Mail SMTP plugin is active, let's go ahead and enable logging. To do this, go to the WP Mail SMTP settings tab (find menu tab at the lower left of the admin page) and click on Email Logs tab at the top.
Check the box next to the Email Log heading and this enables all the basic details of each email. Additionally, you can choose to store the contents of the email. Just remember that if you choose this option, you may be storing sensitive or personal information which may pose a security risk.
By default, WP Mail SMTP records this information and stores in the database:
- Email timestamp (when email was sent),
- Subject line,
- Status of email,
- Email from, to, Ccc, Bcc,
- Email technical details (for debugging)
View Email Logs
You can view emails logged by going back to the WP Mail SMTP menu section and clicking on Email Logs. The display of email logs follows the same pattern as WordPress posts such that the latest emails are at the top. Click on each email log to view details about that particular log.
Logging emails is an important task for effectively managing your website. I have outlined the process of enabling email logs using WP Mail SMTP and hope you'll find this guide useful.