The support forums for BulkWP runs on bbPress and I use wpMandrill to send all emails from BulkWP through the Mandrill App email service from MailChimp. Recently in bbPress v2.5.4 the logic to send topic subscription emails was changed in a major way which broke it for people who were using bbPress with wpMandrill. After spending almost a day debugging I finally got everything to work and thought of documenting it here so that it will be useful for others as well.
What changed in bbPress?
In bbPress till v2.5.4 whenever a new reply was posed to a topic, individual emails were sent to all people who have subscribed to that topic. The major downside to this approach is that if a topic has a lot of subscribers then it resulted in a major bottleneck and in most cases the script used to timeout or the mail server used to crash.
To fix this, in v2.5.4 all subscriber email addresses were moved to bcc and only a single email was triggered for all the subscribers. Also in the “to” a generic do not reply email address was used that was calculated using the domain name.
How this broke wpMandrill?
Unfortunately the above code change broke emails sent through wpMandrill in more than one ways.
Bugs in generating the “do not reply” email address
The following were the different bugs in the code that generated the “do not reply” email address.
- The generated “do not reply” email address which was specified in the “to” filed was enclosed in angle bracket, which Mandrill API didn’t like.
- If the domain name started with
s
, then it was stripped. eg: if the domain name ishttps://ssssean.com/
, then the email address wasnoreply@ean.com
- If the domain name has www, then the generated “do not reply” address also had ‘www’ in the email domain name. eg:
noreply@www.example.com
All of these are documented in this post in bbPress support forum.
No BCC support in Mandrill API
Mandrill API doesn’t support more than one bcc email address and the wpMandrill plugin just used the first bcc address and silently ignored the others. Since the new change added all the subscribed email address to bcc, the email was sent only to the first email address and the rest were silently ignored.
How to fix these issues?
All the issues in generating the “do not reply” email address were fixed in this ticket. In addition to fixing the bugs, two more filters are introduced that allows you to change the default email address to something else if needed. The following are the filter names
- bbp_get_do_not_reply_address
- bbp_subscription_from_email
- bbp_subscription_to_email
The changes are already merged into trunk and hopefully should be available as part of the next release. Till then you might have to manually edit the core file to change the default “do not reply” email address. The relevant code is in bbpress/includes/common/function.php
file in the bbp_notify_subscribers
function (around line number 1065)
Update: The above changes are now available from bbPress 2.5.6. If you are using bbPress 2.5.6 or above then you can change the “do not reply” address using the filters instead of manually editing the core files.
Regarding the issue with bcc support in Mandrill API, I found a way to trigger individual emails for a given list of email address after going over the Mandrill API documentation. Basically you have to sent the different email addresses as array in the “to” file with type set to “bcc” and then set the option preserve_recipients
option to false. This will make Mandrill to trigger individual emails for each of the email address.
After I found about this, I looked into wpMandrill plugin source code to see if this can be done by hooking into the mandrill_payload
filter. But unfortunately that was not possible. After some more debugging I finally found that it would be possible to this by hooking the wp_mail
filter.
I quickly wrote a small plugin which hooks into wp_mail
filter and converts all “bcc” address into the correct format that Mandrill expects. You can checkout the plugin in github. One word of caution. Even though this plugin works in my server, I have not fully tested all the corner cases. So do test this first in your dev server before installing it in a live site.
Limitations
The above plugin only works for the bbp_notify_subscribers
function. But there is a similar function called bbp_notify_forum_subscribers
which sends emails to all people who have subscribed to a forum when a new reply is posted.
Try it out and let me know if you face any issues and hopefully it will be useful for other people who also use bbPress with wpMandrill like me 🙂