Hi @nkeatign
It ought to be totally do-able, but you’ll need to write it. If BuddyPress detects that something has re-implemented WordPress’ wp_mail
function (like the Sendgrid plugin does), then it’ll use the plain text version of the email and pass that to wp_mail
to let the custom wp_mail
implementation deliver the email.
I am not aware of anyone who’s written a Sendgrid implementation for BuddyPress 2.5 yet, because the 2.5 release is still pretty new! Maybe you could write an integration plugin and be the first!
Here’s what you need to do (we can document this process more formally if this works for you): — off the top of my head, not tested, be wary of unexpected dragons, etc —
1) Add add_filter( 'bp_email_use_wp_mail', '__return_false' );
2) Add add_filter( 'bp_send_email_delivery_class', function( $delivery_class ) { return 'Your_Class'; } );
.
These steps tell BuddyPress to always use its own email APIs, and tell it to use the class named Your_Class
to handle the email delivery. The default delivery class is BP_PHPMailer
which uses PHPMailer. I strongly suggest you use it as a reference for implementing a Sendgrid implementation.
Your_Class
needs to implement the interface BP_Email_Delivery
which provides a method bp_email()
, which receives a BP_Email
object. Everything about the email is contained inside the BP_Email
object.
What your bp_email()
method will need to do is call the Sendgrid’s plugin email-sending function. You can get all the information you need (recipients, HTML body, plain text body, etc) from the BP_Email
object.
@djpaul — are you saying that existing sites with transactional email systems will continue to work if they upgrade to 2.5 (we have clients using both SendGrid and Mandrill – via their recommended WP plugins)?
@rogercoathup Hi. Assuming those plugins re-implenment wp_mail()
, as I expect most do, yes. Things will continue to work. They’ll get plain text versions of the BuddyPress emails, just the same as in previous BuddyPress releases (though some emails’ sentences have been tweaked/rephrased).
@rogercoathup Awesome — thanks so much! I will look to develop that and publish something in regards to what I come up with.
@djpaul yeah I had the SendGrid plugin setup yesterday and it was working as expected.. The only obvious issue is it does not include the same nice contextual info like the standard BP emails (e.g “Hi, {{DisplayName}}).
I’m a little surprised that no one has published an existing solution for passing the common variables through to a transactional email service.
Sounds easy enough.
@nkeatign True, but you’ll be able to take the (rendered) HTML and send that to SendGrid, so it’ll send the nice version of the email.
Let me know how you’d get on. I’d love developer feedback regarding building such extensions.
@nkeatign have you made any progress on an integration plugin yet? I’m about to start on one myself, but wanted to see if you’ve published anything yet or found another solution.