Download & Extend

Email Notification for Drupal 6.x

Project:Privatemsg
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:email, notification, pm

Issue Summary

Does anyone know what's the status of Email Notification for Drupal 6.x? I've searched all over and can't find any solutions to that. If that's the case I may be willing to try to write a patch/module for that myself, but don't want to re-invent the wheel. Any suggestions on the best way of going about this would be appreciated.

Comments

#1

There is currently nothing AFAIK.

If you want to write it, I'm suggesting to look at #288183: Provide api function for other modules to send messages. and create the feature as a submodule. With the submit hook, all you need is a hook_privatemsg_message_insert($message) hook and loop through the recipients. And, of course, a configuration option to enable/disable it.

And, as a submodule, it would be easy to replace with something else (mabye rules/notification integration) if someone needs more features.

#2

Thanks for the info. I'm looking into it right now - will post update in this thread.

#3

excellent. I really need this feature for a site I am working on. Let me know when you make some progress on this, or an idea of when this might be working.... under a month?

#4

About a month if not less. I ported my site from phpBB forum to drupal, and that feature is one my users miss most, so it's a priority for me as well.

www.lbshooters.com

#5

Great, feel free to ask if you have questions regarding the API or privatemsg in general.

#6

Started coding the submodule today. It is called pm_email_notify Will keep you guys updated here.

#7

Subscribe. Would love to see this submodule when you're done.

#8

I'm still working on it - have most of it done, but am really busy with a real project at work right now, so have no time to spare. I will have it ready in another week or two.

#9

Subscribing. Thanks eternal for the work. Happy to test the submodule when it's done.

#10

Subscribing. This may very well be the single most important feature one could request at this point. Many thanks for working on it.

#11

Subscribing, have to agree with mjourney2.

#12

Subscribing ... +1/mjourney2

#13

Subscribing. mjourney2 is absolutely right. Many thanks to eternal21 for working on it.

#14

subscribing - if you need a tester, let me know. Also, would sponsorship $ help speed it up?

#15

certainly :)

Feel free to make an offer and hopefully it will catch an eye of some developers willing to help with this issue.

I will gladly review the patch and commit it when its ready.

#16

README.txt for pm_email_notify (last updated: Feb 9, 2009)

pm_email_notify Versions
----------------
Version: 1.0
Released On: Feb 8, 2009
Notes:
1. First build, not part of Drupal versioning system yet.
2. Installed and working on my site (www.lbshooters.com).
3. Needs to be tested by other members of Drupal community.

Version: 1.1
Released On: Feb 9, 2009
Notes:
1. Removed dependency on Subscriptions module by adding own mail function.
2. Removed the need to enter your own Domain in the DEFINE section (using !site instead).
3. To update from version 1.0 simply overwrite .txt, .info, and .module files,
settings won't be affected.

Version: 1.2
Released On: Feb 10, 2009
Notes:
1. Fixed email message text, by using !uri instead of !site (I went with Rachel's template).
2. Fixed indentation and {} placements to adhere to Drupal coding standard.
3. Run the code through coder module and fixed all warnings.
4. To upgrade from version 1.1, simply overwrite all the files, previous settings
won't be affected.

Wishlist
----------------
1. Implement changes pointed out by Berdir:
a) convert default email notification variable to a privatemsg setting
b) get rid of helper function for form notification page
c) use message_submit hook once its commited

Intro
----------------
The original thread discussing pm_email_notify can be found here:
http://drupal.org/node/357093

I (Eternal21) decided to write the pm_email_notify module,
after porting my site from phpBB forum to drupal, and realizing
that Drupal misses many of the features I took for granted in phpBB environment.

This is my first Drupal module, so I'm sure there are better ways
of accomplishing the end result.

Since I'm new to Drupal development, I basically looked at other modules
interacting with privatemsg module (like pm_block_user or privatemsg_filter),
and based interactions of my module on those.

Code Overview
----------------
pm_notify_module performs two basic tasks:
1. It stores whether user wants to be notified of PM's via email or not.
2. It notifies the user of incomming PM's.

The first task is accomplished by storing the preference in pm_email_notify
table inside drupal database. There are two fields - user_id, and
email_notify_is_enabled (1 = enabled, 0 = disabled).

The second task is done through Subscriptions module, by calling it's
mail function.

The call to pm_notify_module email notification hook is placed right after
privatemsg module sends PM. That way email notifications are sent only when
PM is succesfully sent.

Installation
----------------
1. You will need the following modules in order for pm_email_notify
module to work:
-privatemsg (http://drupal.org/project/privatemsg)

If you haven't done so yet - visit the link above and install/enable
the module before proceeding.

2. Download the pm_mail_notify.zip file from the following location:
http://www.box.net/shared/5gpjtx0hi6
Unzip the pm_email_notify.zip file, you will end up with the
following files:
-README.txt
-pm_email_notify.info
-pm_email_notify.install
-pm_email_notify.module

3. Email notifications are enabled for users by default. If you
want to disable email notifications by default, open up the
pm_email_notify.module file with any text editor, and modify
the following line by replacing 1 with 0:

<?php
define
("DEFAULT_EMAIL_NOTIFICATION_SETTING", 1);
?>

4. Create the following folder on your website inside privatemsg directory:
pm_email_notify/
(You can find privatemsg/ directory inside /sites/all/modules/ directory, or
sometimes inside /modules/ directory)

5. Upload the 4 unzipped files into that folder.

6. Log in as admin user into your drupal website, and go to
Administer->Site Building->Modules page.

7. Scroll down to Mail group, and enable the box next to
PM Email Notification module. (NOTE: The box will be grayed out,
if you haven't installed and enabled Privatemsg module first)

This will create a table inside your drupal database
called pm_email_notify that stores users notification preferences

8. The last step of installation is adding a call from privatemsg module
to pm_email_notify module.
a) download the following file from your website:
/privatemsg/privatemsg.module

b) find the following piece of code inside the file (around line 637):

<?php
   
// 2) Save message to recipients.
    // Each recipient gets a record in the pm_index table.
   
$query = "INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES (%d, %d, %d, %d, 0)";
    foreach (
$message['recipients'] as $recipient) {
       
$mid = $message['mid'];
       
$thread_id  = $message['thread_id'];
       
db_query($query, $mid, $thread_id, $recipient->uid, 1);
    }
?>

c) add the two lines at the end of the foreach loop so that you end up with the following:

<?php
   
// 2) Save message to recipients.
    // Each recipient gets a record in the pm_index table.
   
$query = "INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES (%d, %d, %d, %d, 0)";
    foreach (
$message['recipients'] as $recipient) {
       
$mid = $message['mid'];
       
$thread_id  = $message['thread_id'];
       
db_query($query, $mid, $thread_id, $recipient->uid, 1);
       
// 2a) Notify each recipient via email that they have been sent a private message
       
module_invoke('pm_email_notify', 'privatemsg_notify', $message['author'], $recipient);
    }
?>

d) Upload modified file back to your drupal website.

9. At this point PM notifications should be functional. Each user can adjust
their PM notification settings at the following location:
/messages/notify

Further Customization
----------------
To modify the text of notification message, change the 'subject' and 'body'
elements in pm_email_notify_mail function inside pm_email_notify.module.

#17

Status:active» needs work

Thanks for your work so far. I'm trying to give a detailed review, as there are some things that can be improved. If you have any questions, feel free to ask here and also look at the documentation I'm working on at http://drupal.org/node/369399. Also, don't be scared by the lenght of the review, your code is well written, most of my points are about making things easier.. either for the module or for the user.

<?php
//Change the following defines to customize pm_email_notify behavior
//1 = users sent email notifications by default
//0 = users not sent email notifications by default
define("DEFAULT_EMAIL_NOTIFICATION_SETTING", 1);
?>

It would be better if this would be a setting that can be set in the administration. The best would probably be a additional tab at the privatemsg settings, see http://drupal.org/node/288960#comment-1244149 for a patch where I added such a tab with a simple configuration option. Keep in mind that updating to a new version should be as easy as possible. The variable can then by used with variable_get('pm_email_notify_default_notification', 1) and will not be overwritten if the users installs a new version.

<?php
define
("YOUR_DOMAIN_NAME", "http://www.lbshooters.com");
?>

No need to define that on your own. See http://api.drupal.org/api/global/base_url/6. Just add a "global $base_url" where you need it. Also, see later why you don't need that at all.

<?php
function pm_email_notify_menu() {
 
$items['messages/notify'] = array(
   
'title'            => 'Email Notify',
   
'page callback'    => 'pm_email_notify_page',
   
'access arguments' => array('read privatemsg'),
   
'type'             => MENU_LOCAL_TASK,
   
'weight'           => 10
 
);
  return
$items;
}

/**
* This function creates PM Email Notifications page.
*/
function pm_email_notify_page() {
   
$content = '';
   
drupal_set_title('PM Email Notifications');
   
$content .= drupal_get_form('pm_email_notify_user_settings_form');
    return
$content;
}
?>

No need to use a helper function. Use drupal_get_form as 'page callback' and array('pm_email_notify_user_settings_form') as 'page arguments'. You can add the drupal_set_title to the form function. I'm als wondering if that setting wouldn't be better located somewhere under the user account settings, but I'm not sure about that.

<?php
function pm_email_notify_privatemsg_notify($author, $recipient) {
?>

My API Patch #288183: Provide api function for other modules to send messages. will add a a hook_privatemsg_message_submit($message) hook, as soon as that one is commited, it is not necessary to touch privatemsg.module anymore. With that hook you can loop over $message['recipients'] to send the notification mails.

<?php
        $subject
= "You have received a private message from $author->name";
       
$body = "Hi, you have received a private message from $author->name.  To read it, visit ".YOUR_DOMAIN_NAME."/messages.  You can disable these notifications at any time by adjusting your preferences at the following link ".YOUR_DOMAIN_NAME."/messages/notify.";

       
//NOTE:  You can change the following mail function, if you want to use
        //       a different module to send emails (by default subscription module
        //       is used to send emails.

       
$mail_success = drupal_mail('subscriptions_mail',
           
NULL, //$mailkey,
           
$to,
           
user_preferred_language($recipient),
            array(
               
'account' => $recipient,
               
'object' => NULL,
               
'context' => array(
                   
'recipient' => $to,
                   
'subject' => $subject,
                   
'message' => $body,
                ),
            ),
           
$from,
           
TRUE
       
);
?>

According to http://api.drupal.org/api/function/drupal_mail and http://api.drupal.org/api/function/hook_mail/6, you could define your own hook_mail function, where you can define your own texts. No need to use subscriptions then.. Also, have a look at the example of hook_mail at the drupal_mail page, it does use a !site placeholder and makes it possible to translate the notifications texts according to the user settings. You could probably just copy that example and change it a bit.

Last point: I would suggest to install the coder module and check your code. If multiple developers are working on/with the same code, it is imho very important to follow the code styleguide, so that the code is easier to understand. Things like {}-placement, space-intendation (drupal does use 2 spaces, not 4) and so on.

#18

Thanks for the detailed review Berdir. I'll try to implement your recommendations when I get a chance. I come from C/C++ background and just getting into php so bear with me.

#19

very good review Berdir, big props from me :)

#20

Thank you for your work, eternal21 - but sadly, it doesn't do like intended in my environment. Yes of course, I've installed Privatemsg (that's why I'm posting comments here), and I'm running Subscriptions anyway. But I don't get any email whenever I receive a privatemsg, although I exactly followed your installation instructions.

Please don't hesitate to request any information you need from me in case you'd like to examine what might have failed.

#21

Garnerin - I would like to get to the bottom of your problem.

1. Can you see the pm_email_notify table in your Drupal database? Does it save your Yes, No setting?

2. It would also be helpful if you could find out where exactly the code breaks.
Can you add a debug line in the pm_email_notify.module right after this function starts
function pm_email_notify_privatemsg_notify($author, $recipient) {

Simply put in something like:
drupal_set_message(t('I'm inside notify hook!'));

and re-upload the modified file.

Then try sending a PM, if the message shows up, it means the privatemsg module calls the function, and the problem is further down the line. We'll go from there.

#22

Happily subscribing :)

#23

I released a new version of pm_email_notify module. It's now 1.1. Install instructions have been updated as well in the earlier post. The two changes are:

1. I removed dependency on Subscription module - you can now use pm_email_notify, without it.
2. Removed the need to change website 'define'.

#24

Eternal21,

back to the "bottom of my problem" before I proceed and try out your new version:

1. Yes, I see the table "pm_email_notify" with one entry: user_id = 15 (This is the right ID of one of two users I've granted access to PMs for test purpose; the other one should run the default), email_notify_is_enabled = 1.

2. I did as suggested, but I did not get any message at all. Obviously, the function is not called at all.

Or have I destroyed your function? I cannot find my error:

<?php
function pm_email_notify_privatemsg_notify($author, $recipient) {
   
//DEBUG
   
drupal_set_message(t('CALLED: pm_email_notify_privatemsg_notify()'));
   
drupal_set_message(t('pm_email_notify_privatemsg_notify('.$author.', '.$recipient.')'));
   
//check if recipient enabled email notifications
   
if (get_user_notification_setting($recipient->uid))
    {
       
//DEBUG
       
drupal_set_message(t('get_user_notification_setting('.$recipient->uid.')'));
       
//send them a new pm notification email if they did
       
$to = $recipient->mail;
       
//DEBUG
       
drupal_set_message(t('$to = '.$to));
       
//NOTE:  You can change the following two lines ($subject and $body) to
        //       customize your notification email appearance
        //$subject = "You have received a private message from $author->name";
       
$subject = "Du hast eine Private Mitteilung von $author->name erhalten";
       
//DEBUG
       
drupal_set_message(t('$subject = '.$subject));
       
//$body = "Hi, you have received a private message from $author->name.  To read it, visit ".YOUR_DOMAIN_NAME."/messages.  You can disable these notifications at any time by adjusting your preferences at the following link ".YOUR_DOMAIN_NAME."/messages/notify.";
       
$body = "Hallo, Du hast eine Private Mitteilung von $author->name erhalten. Um sie zu lesen, besuche die Seite ".YOUR_DOMAIN_NAME."/messages. Du kannst diese Art der Benachrichtigung jederzeit auf der Seite ".YOUR_DOMAIN_NAME."/messages/notify ändern.";
       
//DEBUG
       
drupal_set_message(t('$body = '.$body));

       
//NOTE:  You can change the following mail function, if you want to use
        //       a different module to send emails (by default subscription module
        //       is used to send emails.

       
$mail_success = drupal_mail('subscriptions_mail',
           
NULL, //$mailkey,
           
$to,
           
user_preferred_language($recipient),
            array(
               
'account' => $recipient,
               
'object' => NULL,
               
'context' => array(
                   
'recipient' => $to,
                   
'subject' => $subject,
                   
'message' => $body,
                ),
            ),
           
$from,
           
TRUE
       
);
       
//DEBUG
       
drupal_set_message(t('$mail_success = '.$mail_success));
    }
}
?>

#25

What?! :-O

Suddenly I notice the email notifications I could have expected from my 'debug' test PMs which should trigger the debug messages! -- I have still not installed your update... Indeed, I didn't change anything but inserting the 'debug' lines as you suggested.

I'm quite perplex...

I think we should stop further examinations here, I've got the feeling that they're going to be useless and of no avail. Let's concentrate on your new version.

#26

Great! This version runs straightaway -- nearly, except one little thing: Replace !site by !uri in the email body where you intend to place a link. !site is the name of the website, !uri is its address.

However, a thousand thanks for your work!

#27

> Great! This version runs straightaway -- nearly, except one little thing: Replace !site by !uri in the email body where you intend to place a link. !site is the name of the website, !uri is its address.

Oh, that was my mistake then..

#28

Garnerin - that's strange indeed that you wouldn't see your debug messages and still get the PM's, but since the new version (1.1) works for you we'll just stick to that. Also - I'll put in the !site -> !url change tonight - thanks for that.

#29

> I'll put in the !site -> !url change tonight

Please note that it's not "!url" but "!uri" -- just to keep you from possible confusion and unnecessary extra work.

#30

Thanks for this, it is working GREAT!.

I changed the email to match the messages I get from Ubercart - I believe they are using pm-lite that Ryan wrote. Here is what the email looks like:

SUBJECT: New private messages at {site}.

BODY:
Hi {user},
This is an automatic reminder from the site {site}. You have received a new private message.

To read your message, follow this link:
http://{site}/messages

If you don't want to receive these emails again, change your preferences here:
http://{site}/messages/notify

Code:

            $message['subject'] = t('New private messages at !site.', $variables, $language->language);
            $message['body'] = t("Hi !username,\n\nThis is an automatic reminder from the site !site. You have received a new private message.\n\nTo read your message, follow this link:\n!uri/messages\n\nIf you don't want to receive these emails again, change your preferences here:\n!uri/messages/notify", $variables, $language->language);

(Edited to correct sample of email text)

#31

Released the latest version 1.2, with Garnerin's fix. I used RachelNY's email template in this release.

I also reformatted the code so it adheres to Drupal's coding style, and ran it through coder module, to make sure there are no outstanding warnings.

The latest version (v1.2) can be downloaded here:
http://www.box.net/shared/5gpjtx0hi6

#32

Thanks again for taking this on, this was a sorely needed feature. Seems to be working very well ... glad I could contribute a line of code for you!

#33

PERFECT!!!!!!!!!!!!!!!!!!!!!!!!! Thank you thank you thank you!!!

May I nitpick a tiny bit? Change "Receive email notification for incomming private messages?" to INCOMING (one M)

Apart from that, it works perfectly :)

#34

@eternal21: it is very difficult to track progress/changes if you keep updating your original post. perhaps you could post updates as actual comment reply?

#35

README.txt for pm_email_notify (last updated: Feb 10, 2009)

pm_email_notify Versions
----------------
Version: 1.0
Released On: Feb 8, 2009
Notes:
1. First build, not part of Drupal versioning system yet.
2. Installed and working on my site (www.lbshooters.com).
3. Needs to be tested by other members of Drupal community.

Version: 1.1
Released On: Feb 9, 2009
Notes:
1. Removed dependency on Subscriptions module by adding own mail function.
2. Removed the need to enter your own Domain in the DEFINE section (using !site instead).
3. To update from version 1.0 simply overwrite .txt, .info, and .module files,
settings won't be affected.

Version: 1.2
Released On: Feb 10, 2009
Notes:
1. Fixed email message text, by using !uri instead of !site (I went with Rachel's template).
2. Fixed indentation and {} placements to adhere to Drupal coding standard.
3. Run the code through coder module and fixed all warnings.
4. To upgrade from version 1.1, simply overwrite all the files, previous settings
won't be affected.

Wishlist
----------------
1. Implement changes pointed out by Berdir:
a) convert default email notification variable to a privatemsg setting
b) get rid of helper function for form notification page
c) use message_submit hook once its commited
d) fix 'incomming' spelling.

Installation
----------------
1. You will need the following modules in order for pm_email_notify
module to work:
-privatemsg (http://drupal.org/project/privatemsg)

If you haven't done so yet - visit the link above and install/enable
the module before proceeding.

2. Download the pm_mail_notify 1.2.zip file from the following location:
http://www.box.net/shared/5gpjtx0hi6
Unzip the pm_email_notify.zip file, you will end up with the
following files:
-README.txt
-pm_email_notify.info
-pm_email_notify.install
-pm_email_notify.module

3. Email notifications are enabled for users by default. If you
want to disable email notifications by default, open up the
pm_email_notify.module file with any text editor, and modify
the following line by replacing 1 with 0:

<?php
define
("DEFAULT_EMAIL_NOTIFICATION_SETTING", 1);
?>

4. Create the following folder on your website inside privatemsg directory:
pm_email_notify/
(You can find privatemsg/ directory inside /sites/all/modules/ directory, or
sometimes inside /modules/ directory)

5. Upload the 4 unzipped files into that folder.

6. Log in as admin user into your drupal website, and go to
Administer->Site Building->Modules page.

7. Scroll down to Mail group, and enable the box next to
PM Email Notification module. (NOTE: The box will be grayed out,
if you haven't installed and enabled Privatemsg module first)

This will create a table inside your drupal database
called pm_email_notify that stores users notification preferences

8. The last step of installation is adding a call from privatemsg module
to pm_email_notify module.
a) download the following file from your website:
/privatemsg/privatemsg.module

b) find the following piece of code inside the file (around line 637):

<?php
   
// 2) Save message to recipients.
    // Each recipient gets a record in the pm_index table.
   
$query = "INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES (%d, %d, %d, %d, 0)";
    foreach (
$message['recipients'] as $recipient) {
       
$mid = $message['mid'];
       
$thread_id  = $message['thread_id'];
       
db_query($query, $mid, $thread_id, $recipient->uid, 1);
    }
?>

c) add the two lines at the end of the foreach loop so that you end up with the following:

<?php
   
// 2) Save message to recipients.
    // Each recipient gets a record in the pm_index table.
   
$query = "INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES (%d, %d, %d, %d, 0)";
    foreach (
$message['recipients'] as $recipient) {
       
$mid = $message['mid'];
       
$thread_id  = $message['thread_id'];
       
db_query($query, $mid, $thread_id, $recipient->uid, 1);
       
// 2a) Notify each recipient via email that they have been sent a private message
       
module_invoke('pm_email_notify', 'privatemsg_notify', $message['author'], $recipient);
    }
?>

d) Upload modified file back to your drupal website.

9. At this point PM notifications should be functional. Each user can adjust
their PM notification settings at the following location:
/messages/notify

Further Customization
----------------
To modify the text of notification message, change the 'subject' and 'body'
elements in pm_email_notify_mail function inside pm_email_notify.module.

#36

subscribe

#37

Works great! Thank you!

#38

Hi,

Thanks for your efforts with this patch. When will this be added into the actual privatemsg module?

Thanks

#39

When it's ready :)

Other things are currently more important, for example #288183: Provide api function for other modules to send messages.. Actually, the api patch will remove the need to patch privatemsg.module to make this work. This will make this module very easy to install and test.

#40

@eternal21

The api patch has now been commited. So you can switch to the use hook_privatemsg_message_insert hook. Please ask if you have any questions.

#41

Assigned to:Anonymous» eternal21

Will work on it when I get a chance, hopefully later on this week.

#42

Subscribing... is it possible to just download the submodule and have this work?

#43

Not yet, but it will be as soon as the module is updated to use the new API.

#44

One question -
if the the text of the notification message can be changed only by changing the file, that meens we can't translate that to languages using non-english letters (Hebrew, in my case).
any solutions ?
Thanks

#45

The strings are wrapped in t() calls and can easily be translated.

#46

@eternal21
Do you have any plans to fix the open issues soon, like using the privatemsg api hooks ?

If not, I can do it, but I would like to encourage other users to participate in the development, if they are interested :) On the other side, this is an often requested feature, and I want to make it easy to install and configure.

#47

Sorry. Long story short - you'll notice my website was suspended, and I have no other setup to test at the moment. In other words - the best bet is if you complete the open issues, and get the whole thing wrapped up. Thanks.

#48

Assigned to:eternal21» Anonymous
Status:needs work» needs review

No problem.

Attached is an updated version, which needs the latest -dev of privatemsg.module version to work. It is not needed to change privatemsg.module anymore. extract it, enable it, and it should work.

Changes:

- use the privatemsg api
- provides a admin settings page, with can be used to set the default user setting, subject and body of the notification mail.
- used the coder tough love module at http://drupal.org/project/coder_tough_love to improve the apidoc and wording (e-mail <-> mail and so on)

AttachmentSizeStatusTest resultOperations
pm_email_notify-1.tar_.gz4.37 KBIgnored: Check issue status.NoneNone

#49

Tested it, works flawlessly, except for a few things:

- the Email Notify Tab gives a WSOD now
- I can't for the life of me find the settings

Apart from that, perfect, thanks!

#50

- WSOD ?
Can't reproduce that. Make sure you are using the latest -dev version, it's only tested against this. I have no idea what could cause this, there is only a single, simple, function call on that page, except of that, it's a simple form. Unless you can enable PHP error reporting and give me a php error message, I can't help you on that..

- I can't for the life of me find the settings
The settings page should be displayed as a local task at admin/settings/messages. The direct path is admin/settings/messages/notify. The default local task was added recently in another patch, so again, make sure you are using the latest -dev version. Please check if there is a default local task "Private messages" in the settings page, and if you have the privatemsg_filter module enabled, also a Filter local task.

#51

Hah! All I did was disable private message in the modules page, and enable it again, and now it works perfectly. Thanks again for one of the best modules around, one of our favorites!

#52

Our users did find a bug after all, and it is consistent: it is not possible to unsubscribe to e-mail notification. If they tick "Disabled" and click "Save configuration", immediately it jumps back to "Enabled". I verified it both on the test site and our live site.

#53

Confirmed and fixed.

AttachmentSizeStatusTest resultOperations
pm_email_notify-2.tar_.gz4.41 KBIgnored: Check issue status.NoneNone

#54

That was fast! I just told our fellow game fans that the Drupal community is awesome, and I mean it. I am so happy we decided to move across to Drupal, phpBB in combination with Joomla was nothing but a pain.

#55

I'm sitting in a IT Law course, which isn't really interesting :)

#56

Great work!

So when will this module be officially released on drupal? Or will it be combined?

Thanks!

#57

It doesn't have a high priority right now and will most probably not be part of the 1.0 release. But it is easy to install, just copy it to the privatemsg folder and when it will be included in privatemsg, it will automatically overwrite the manually installed version.

#58

I haven't investigated it thoroughly but when I enable the email notifications module, I get double the private messages? So each message I send turns into two.

-Matt

#59

The module wasn't behaving properly if the user hadn't set their permissions yet. This function needed to be changed from:

<?php
function _pm_email_notify_is_enabled($uid) {
 
$sql = 'SELECT email_notify_is_enabled FROM {pm_email_notify} WHERE user_id = %d';
 
$mail_notification_enabled = (int)db_result(db_query($sql, $uid));
  if (!
$mail_notification_enabled === NULL) {
   
$mail_notification_enabled = variable_get('pm_email_notify_default', PM_EMAIL_NOTIFY_ENABLE);
  }

  return
$mail_notification_enabled;
}
?>

to this:

<?php
function _pm_email_notify_is_enabled($uid) {
 
$sql = 'SELECT email_notify_is_enabled FROM {pm_email_notify} WHERE user_id = %d';
 
$mail_notification_enabled = db_result(db_query($sql, $uid));
  if (
$mail_notification_enabled == NULL) {
   
$mail_notification_enabled = variable_get('pm_email_notify_default', PM_EMAIL_NOTIFY_ENABLE);
  }

  return
$mail_notification_enabled;
}
?>

The cast to int was causing an empty result to be zero, which meant that everyone defaults to not getting messages no matter what the site level settings were.

Here's the diff...

135,136c135,136
< $mail_notification_enabled = db_result(db_query($sql, $uid));
< if ($mail_notification_enabled == NULL) {
---
> $mail_notification_enabled = (int)db_result(db_query($sql, $uid));
> if (!$mail_notification_enabled === NULL) {

#60

Status:needs review» needs work

I see, but If I'm correct, your code is also wrong. Imho, the (int) needs to removed and checked with "=== FALSE", because we only want to use the default if no record has been found in the database. Your code would also use the default value if the user has explicitly disabled the feature.

PS: Your diff is the wrong way and you should use diff -up

#61

Updated the enable function, please try again, it should work now.

AttachmentSizeStatusTest resultOperations
pm_email_notify-3.tar_.gz4.41 KBIgnored: Check issue status.NoneNone

#62

Status:needs work» needs review

#63

Let me first give major thanks to eternal21, Berdir, and everybody else who helped with this functionality. It is awesome and much appreciated.

I wanted a couple more tokens available for the notifications being sent, so I rolled this attached patch. It adds !author for the username of the person sending the message, !pm_subject, and !pm_body.

I also tweaked the default message slightly to use the !author token.

More tokens can easily be created by modifying the new _pm_email_notify_token method.

Thoughts?

AttachmentSizeStatusTest resultOperations
pm_notify_357093_63.patch2.36 KBIgnored: Check issue status.NoneNone

#64

Nice idea. A few things to consider:

- Security: You should imho remove html code in the body and subject with strip_tags()
- Maybe adding the thread_id as a token, too ? This would make it possible to directly link to the message (messages/view/!thread)
- A description added to the body field in the admin settings screen would be nice, explaining the aviable tokens.

Oh, and feel free to directly update the module.

#65

I made the suggested changes.

Also, note that there was a bug on line 164 of Berdir's tarball from comment 61 that is fixed both in my patch and in this tarball.

AttachmentSizeStatusTest resultOperations
pm_email_notify-4.tar_.gz4.74 KBIgnored: Check issue status.NoneNone

#66

Looks good, nice catch with my "notifiy" :)

Just a minor comment. The description is splitted up in three parts. I can see why you moved the !... stuff outside of the t call, but it should also work if you have only a single t() call with a parameter to insert the fields. Something like

<?php
t
('sentence 1. sentence 2: !params', array('!params' => 'list of available params'))
?>

#67

I know that was a little weird. I copied the format that user module used to do the same thing. So blame the core guys :)

#68

Hello everyone,

Thanks a lot for the hard work getting this together. I have not been able to get it to work properly. Still not getting emails notifying me of private messages.

My steps:

- Installed latest version of private message 6.x-1.x-dev
- Installed email notify within the private message folder from #65
- Modified private_message.module
- Ran update.php

I am getting the private messages but still not getting emails notifying me of them. I am not using the messaging framework but the comment notify module and it is working fine

Any ideas of where to start troubleshooting?

Many thanks for any help,

Raul

#69

You don't need to modify the privatemsg.module file anymore but make sure it contains the following line inside the function "_privatemsg_send" (second-last line):

<?php
module_invoke_all
('privatemsg_message_insert', $message);
?>

If it is not there, it's not the latest version of that file.

#70

Hi Berdir,

Thanks for the super quick reply. Amazing work. Yes, for some reason it did not get updated. Now I got another issue. When I click the send private message link the private message is not calling the username of the user I am trying to send the private message to so I have to write it again. Any idea of what could be happening?

Thanks

#71

sorry, but I can't really unterstand what you're talking about. Please try to explain it again (maybe with screenshots or something to explain it).

Also, it doesn't seem to be related to email notification, so please open a new support request. Everytime a new comment is made in this issue, a mail is sent to 20+ subscribers ;)

#72

Hi,

Me again.

I uninstalled, reinstalled email notify and then ran updata.php and it is working fine now.

Thanks a lot for the super quick reply

Good luck everyone.

I just launched my new community today. if any one wants to give em some feedback or maybe ask abotu any of the things I did there jsut let me know. www.cancerconnections.com.au

#73

I just got this notifications plugin working for privatemsg(6.x).

http://drupal.org/node/413370

#74

Hello eternal21,

I've been doing some digging around this problem in v4, and it looks like the $message array being passed to the pm_email_notify_privatemsg_message_insert() function is empty - I was getting a PHP error because $message wasn't an array, and no messages are being sent.

Also, I can't see the admin panel and no e-mails are being sent, and I'm at a bit of a loss as to how to diagnose the problem. Any ideas?

<?php
/**
* Implementation of hook_privatemsg_message_insert().
*/
function pm_email_notify_privatemsg_message_insert($message) {
  if (
count($message['recipients']) > 0) {
    foreach (
$message['recipients'] as $recipient) {
     
// check if recipient enabled email notifications
     
if (_pm_email_notify_is_enabled($recipient->uid)) {
       
// send them a new pm notification email if they did
       
$params['recipient'] = $recipient;
       
$params['message'] = $message;
       
drupal_mail('pm_email_notify', 'notice', $recipient->mail, user_preferred_language($recipient), $params);
      }
    }
  }
}
?>

For the record, I have tried uninstalling and reinstalling the Privatemsg module, enabling it and disabling it, and nothing so far has helped :o(

Thanks for any help you can offer!

Al

#75

Are you using the -dev version?

#76

Works great.

I just downloaded the latest dev version of privatemsg module and added the v4 of pm_email_notify from #65. I didn't have to hack any modules, just enabled and it worked.

Good work.

#77

Would it be possible to roll this into the next release? This functionality is critical to a robust private messaging system.

#78

Its going in :)

I am going to create a follow up issue very soon that requests throttling feature that limits how many notifications and frequency of the notifications that email may receive per day.

That feature requests is considered to be critical because improper use of email notifications may very quickly result in the website using this feature to be blacklisted :(.

You can start on that feature now, but dont continue it in this thread.

#79

Please review this module in conjunction with pm notify: http://drupal.org/project/queue_mail

Instead of implementing our own throttling perhaps we should use an already made and supported module. however i dont want to point users to that module unless its well tested. Please report bugs you find to http://drupal.org/project/queue_mail issue queue and create an issue requesting module maintainer to create an official release for d6.

Thanks.

#80

Status:needs review» fixed

With several modifications from me, this module went into pmsg core.

Thanks everyone :)

notes:
1) I removed README.txt as it contained too much information which was not relevant to the module and has a lot of outdated information.
2) We need to add text on /admin/settings/messages/notify explaining the risk of getting blacklisted if feature is used without throttling. As well as pointing the users to install http://drupal.org/project/queue_mail as preventative action. However we must help review http://drupal.org/project/queue_mail so it can finally have an official release.

Thanks :-p.

#81

I don't see this line in either the 6.x-1.0-rc2 version or the HEAD (development version) of the Privatemsg module. I get all the options appearing when I use the pm_email_notify from #65, but no messages are sent. Where can I get the correct version of Privatemsg?

EDITED:

I meant this line:

<?php
module_invoke_all
('privatemsg_message_insert', $message);
?>

#82

Use the -dev version. HEAD should not be used anymore.

#83

Thanks for the fast reply. I don't see a -dev version at http://drupal.org/project/privatemsg. Do you mean privatemsg 6.x-1.x-dev from http://drupal.org/node/3279/release?api_version[]=87 ? Sorry if this question is kinda noobie.

#84

Yes, exactly, 6.x-1.x-dev.

That version already contains pm_email_notify, you don't need to install anything else, just enable the module.

#85

Yes - works beautifully. Thanks @Berdir.

#86

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#87

I checked module, and "Receive email notification for incoming private messages?" at messages/notify doesn't seems to work, even though I checked no I'm still getting notifications on email.

#88

Status:closed (fixed)» active

#89

Status:active» closed (fixed)

Don't reopen closed threads, create new ones instead. I'm pretty sure this is working correctly, are any mails sent from your site, when you register a user for example?

#90

I wrote that I'm getting email notifications when I check that I don't wan't them.