# HG changeset patch # User Gerard Krijgsman # Date 1446658207 -3600 # Wed Nov 04 18:30:07 2015 +0100 # Node ID dddf0b909346c3073b544b4401d0f4367b0c8e22 # Parent 0000000000000000000000000000000000000000 Added files to version control diff --git a/product-mandrill.xml b/product-mandrill.xml new file mode 100644 --- /dev/null +++ b/product-mandrill.xml @@ -0,0 +1,15 @@ + + + + Mandrill fix + mail_send + + options['webmasteremail'].'>'.$delimiter;]]> + + + diff --git a/readme.txt b/readme.txt new file mode 100644 --- /dev/null +++ b/readme.txt @@ -0,0 +1,53 @@ +Mandrill support for vBulletin v1.0 +======================================== +by GHDpro + +Mandrill.com is email distribution platform which makes it easy to see if mail is delivered or not. Integration with vBulletin is fairly easy, I've written a plugin and a small PHP file to make it work better. + +At this time this mod is fairly simple, it adds one plugin (to the default "vBulletin" product) and a PHP file you will have to edit to make it work. + +Both the plugin and the PHP file seem to work fine under both vBulletin 3 and 4 (latest version). + +Basic Setup +---------------------------------------- + +Using Mandrill is fairly easy, sign up for an account, create an Mandrill API key (in Settings) and enter the required information in vBulletin Options in the "Email Options" section. *"SMTP Secure Connection"* should be set to TLS. + +For security you might want to configure the Mandrill API key to only work from your forum server's IP address and only allow SMTP and nothing else. + +To find out the IP for your forum server, send a test mail (from the vBulletin Admin CP: *Maintenance -> Diagnostics*, second option) and then check the "API logs" in Mandrill (in Settings). + +To only allow SMTP, edit the API key and tick *"Only allow this key to use certain API calls"* and then tick only the *Send-raw* option out of the list. + +Contact Us problem +---------------------------------------- + +There is a problem with vBulletin where it will send messages using the "Contact Us" forum on behalf of the user. This will pollute your Mandrill account: + +[![Sending Domains](http://i.imgur.com/On7yr2at.png)](http://i.imgur.com/On7yr2a.png) [![Senders List](http://i.imgur.com/QfukbUAt.png)](http://i.imgur.com/QfukbUA.png) + +To avoid this problem, the included **product-mandrill.xml** file contains a plugin that will rewrite the *"From:"* field in emails send by vBulletin to always be your webmaster's email address (as you set in vBulletin Options). + +*If you use Mandrill sub-accounts, you can also set the sub-account name by editing the plugin.* + +Webhook +---------------------------------------- + +The webhook is probably the best demonstration how Mandrill can be useful. It completely automates handling of bounced mail. + +What the webhook does is, if Mandrill detects a bounce/rejected mail, it will post information to the webhook PHP script. The script will then look up the email address supplied by Mandrill in the vBulletin user list and move the account to the *"Users Awaiting Email Confirmation"* group (usergroupid: 3). To avoid admins/mods getting moved (and demoted) it will only do this for users in the "Registered Users" group (usergroupid: 2). + +You add the webhook in Mandrill (in Settings -> Webhooks) by specifying the complete URL to the file and enable the *"Message is Bounced / Marked as Spam / Rejected"* (3x) event triggers. + +Then edit the PHP file (be sure to upload it again after you are done) and set the exact webhook URL and key into the variables at the top. Make sure there are no extra spaces or it will not work. + +If you want to see if it is working also set the `$webhook_logfile` variable to a file that must be writable by the webserver (by setting the right file and/or directory permissions). + +What you can then do is add a notice in the Notice manager to display a warning to those in the *"Users Awaiting Email Confirmation"* group to update their email address: + + Hello {username}, your forum account needs to be activated. +

+ You will not be able to post or upload a custom avatar until you activate your account. To activate your account, follow the instructions in the activation email.

+ If you've just joined the forum, the email has already been sent and you should receive it shortly. If you have not received it, you can request it again.

+ If you have been registered for a while your email address might be incorrect. If we detect too many emails to your email address bouncing (meaning it comes back to us with an error) we will mark your account for reactivation. You should check the email address set in your profile.

+ Note: Some email providers incorrectly mark activation emails as spam. Make sure you check your spam/junk folder before contacting us for assistance.

diff --git a/upload/mandrill_webhook.php b/upload/mandrill_webhook.php new file mode 100644 --- /dev/null +++ b/upload/mandrill_webhook.php @@ -0,0 +1,90 @@ +event, $process_events)) + { + $sql = 'SELECT userid, usergroupid FROM '.TABLE_PREFIX."user WHERE email = '".$vbulletin->db->escape_string($event->msg->email)."' LIMIT 0,1"; + $result = $vbulletin->db->query($sql); + if ($result && ($result->num_rows > 0)) + { + $row = $vbulletin->db->fetch_array($result); + if (in_array(intval($row['usergroupid']), $member_usergroups)) + { + $sql = 'UPDATE '.TABLE_PREFIX.'user SET usergroupid = '.intval($email_confirmation_group).' WHERE userid = '.intval($row['userid']); + $result = $vbulletin->db->query($sql); + WebhookLog('Moved account '.intval($row['userid']).' ('.$event->msg->email.') to the "Users Awaiting Email Confirmation" usergroup'); + } + elseif (intval($row['usergroupid']) == intval($email_confirmation_group)) + WebhookLog('Account '.intval($row['userid']).' ('.$event->msg->email.') is already in the "Users Awaiting Email Confirmation" usergroup'); + else + WebhookLog('Account '.intval($row['userid']).' ('.$event->msg->email.') has invalid usergroup: '.intval($row['usergroupid'])); + } + else + WebhookLog('Email address not found: '.$event->msg->email); + } + else + WebhookLog('Invalid event: '.$event->event); + } +} + +function MandrillSignature($webhook_key, $url, $params) +{ + $signed_data = $url; + ksort($params); + foreach ($params as $key => $value) + { + $signed_data .= $key; + $signed_data .= $value; + } + return base64_encode(hash_hmac('sha1', $signed_data, $webhook_key, true)); +} + +function WebhookLog($message) +{ + global $webhook_logfile; + if (!empty($webhook_logfile)) + { + $fp = fopen($webhook_logfile, 'a'); + $ip = (isset($_SERVER['REMOTE_ADDR']) ? ' ('.$_SERVER['REMOTE_ADDR'].')' : ''); + fwrite($fp, '['.date('Y-m-d H:i:s').'] '.$message.$ip."\n"); + fclose($fp); + } +}