I see that it’s been eight years since my last blog post on this website, a tutorial post which also happened to be about MailPoet. I have eleven other blog posts that I never actually started, or started and did not finish, that are still in the draft stage. All that to say that I am still building WordPress websites, but life got too busy for regular and consistent blogging.
Anyhow, while MailPoet has its quirks and issues, I still think it’s the best option for sending newsletters, post notifications, and other similar emails from WordPress.
A few months ago I was getting several client websites set up for sending emails and thought I’d try the MailPoet Sending Service instead of Amazon SES, which I’d used for years. The main draw to MailPoet’s sending service for me was the automatic bounce and complaint handling in the MailPoet back end of your WordPress website. Not having to manually update multiple bounced subscribers each time a newsletter goes out is a big plus.
However, for one of those clients we were sending out a newsletter letting their users know about their redesigned website, and when we started sending the emails we were quickly shut down by MailPoet because of too many bounces. Now granted, I should have used an email list cleaning service such as emailable before we started sending, but that didn’t happen for whatever reason.
The problem, which is what inspired this solution and blog post, was that there is no readily accessible way to know which emails were sent, which emails were not sent, or any other detailed information about the emails. I did contact MailPoet and someone there did eventually send me two CSV files, one that listed “discarded” emails, and another that listed “not delivered” emails. That information helped, but I had to wait three days to get it.
I’ve been using Postmark to send transactional emails from all my client websites since 2019. The price is right ($10 per month for up to 10,000 emails), they have a WordPress plugin, and the detailed information for each email that is sent can be very helpful. That detailed information includes events such as processed, delivered, opened, and clicked.
In late 2020 they added broadcast emails to their available offerings, but I didn’t start using that feature until a few months ago, as mentioned earlier in this article. The challenge or hurdle that I really wanted to overcome was linking MailPoet with Postmark so that bounces and complaints were handled automatically in MailPoet.
Why do this?
There are lots of good reasons. Here are three:
- Automatic bounce, complaint, and unsubscribe handling within MailPoet, without using the MailPoet sending service. (Sorry MailPoet!)
- Let’s say you have a WooCommerce (or other ecommerce) site, and a customer enters their email address incorrectly and their order confirmation email bounces. You will be notified by email and you will have the opportunity to edit the order details and potentially fix the email address they entered by mistake.
- I have a client whose Google Account email stopped working due to the payment credit card expiring that Google had on file. When her website tried to send her new order notification emails they bounced, and I was notified. I was then able to let her know via phone that her email was no longer working.
One caveat with Postmark
Postmark automatically includes an unsubscribe link to each Broadcast email that suppresses that email address in their system. So if you include a MailPoet unsubscribe link in the footer of your email, there will be a second unsubscribe link at the very bottom of the email. No big deal, and if someone clicks that Postmark link rather than the MailPoet link, they will still be unsubscribed in MailPoet if you implement the code and process described below.
Not just for MailPoet emails
I’m using this code and process on all my client websites that send emails for any reason, not just MailPoet emails. As I mentioned above in the “Why do this?” section, this lets you be alerted to any email delivery issues.
Where to put this code
Add the code to a core functionality plugin (best choice), its own plugin, or functions.php.
Steps to implement this process
- Modify the above code as follows:
- Change website URL in the function documentation block
- Change the $site variable in email information
- Change the $to variable in email information
- Temporarily uncomment error_log() in four places
- Optional: In wp-config.php temporarily enable (by setting to “true”)
- define( ‘WP_DEBUG’, true );
- define( ‘WP_DEBUG_LOG’, true );
- define( ‘WP_DEBUG_DISPLAY’, false ); // If this is set to true then the errors will be visible on the front end to everyone
- Go to https://account.postmarkapp.com/servers and click on the Postmark server that you’ll be connecting to.
- Click on Broadcast emails, then Webhooks, and then the Add webhook button.
- (You may need to create the Broadcast emails message stream if you don’t see it.)
- Add the webhook URL. For example:
- Check the event boxes for:
- Spam Complaint
- Subscription Change
- Test all three events using the “Send test” button and feature on that page.
- Optional: If debugging is set to true (see step 2 above) check the debug.log in the wp-content directory.
- If there’s nothing there, you probably have an admin redirect in place. If so, add this to the redirect conditional:
- && ‘/wp-admin/admin-post.php’ != $_SERVER[‘PHP_SELF’]
- Now repeat steps 4 through 8 for Transactional emails.