Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In building a lot of custom workflows, I've found that the ability to send an email to all users of a role would be useful, so here's a patch against 6.x-1.11 which provides a new "Send a tokenized email to users of a role..." action. It's got fairly robust error checking.
Enjoy!
Comment | File | Size | Author |
---|---|---|---|
#47 | tokenized_email_by_role.zip | 3.12 KB | flamingvan |
#46 | tokenized_email_by_role.zip | 2.73 KB | flamingvan |
#42 | new_role_email_action6.patch | 5.74 KB | 5t4rdu5t |
#37 | NoTrigger.png | 60.15 KB | flips |
#25 | new_role_email_action5.patch | 5.5 KB | Agileware |
Comments
Comment #1
Steven Merrill CreditAttribution: Steven Merrill commentedThis patch adds one small but desirable bit over the last one - a #default_value for the form, so that the value isn't eradicated upon going back and editing the advanced action.
Comment #2
gregglesThis seems pretty handy to me. Two questions:
1) The style of the recipient query seems weird:
I don't think I've ever seen a query like that in Drupal. More common seems to be one big long line which is what I'd prefer.
2) I think it would be better to put the drupal_mail inside of the for loop and send one e-mail per person in the role. First, that makes the watchdog error more specific. Second (and I haven't tested this, soo...) I'm assuming that putting all the recipients on the to: line will mean that all members of a role will see the e-mail addresses for that role. For privacy reasons it's important we don't let that happen.
Sending mails in a tight loop like that can be a performance issue if the role is really big, but we have solutions like http://drupal.org/project/queue_mail for that.
Comment #3
Ylan CreditAttribution: Ylan commentedWill this functionality be added to token actions? It seems very usefull to me. This project also does role based email actions, only it doesn't use token.
Comment #4
mudd CreditAttribution: mudd commentedSubscribe
Comment #5
michaelfavia CreditAttribution: michaelfavia commentedsubscribe as well. I can clean up this patch if wed like to push it forward. Using email acton role until it is mainlined
Comment #6
gregglesI think it's just missing a code-style re-roll. Please do re-roll/test and I'll test/commit.
Comment #7
johnmunro CreditAttribution: johnmunro commentedvery interested in this too
Comment #8
not_Dries_Buytaert CreditAttribution: not_Dries_Buytaert commentedI fully agree with 'greggles' 2nd remark that:
2a) for monitoring/ maintenance purposes, each email should be send separately (so logging/ watchdog errors become more specific).
2b) for privacy reasons recipients should NOT be able to determine to which other users the tokenized email is send (let alone expose their email addresses).
As this feature request is applicable to any current version and in order to prevent duplicate submissions of this feature request, I changed the version to the latest currently available. Please correct me, if the best practice in such cases is different.
Comment #9
mudd CreditAttribution: mudd commentedI agree -- it would be nice to have a choice between (A) all recipients in the To: field, and (B) private recipients, either by sending separate emails or by using the Bcc field. But to have only (A) is a privacy problem.
In this post #267921: All recipients visible on outgoing mails, jeff gives us a patch for module Action email role that (I think) provides a check box in Action|configure to make this choice.
BUT, he states "Instead of multiple calls to drupal_mail()..." -- Token.module appears to call drupal_mail() with a list of recipients it extracted from the role. By inspecting drupal_mail() and drupal_mail_send() I see that it's up to the module coder to call drupal_mail separately for each recipient (too bad 'private' isn't an available parameter!).
This is an important topic for me, so if necessary I'll find someone to patch Token; I'd just need a consensus on how to proceed.
Comment #10
gregglesWhat about bcc? I've never done it, but can't Drupal send using one call to drupal_mail and bcc to achieve "private"?
Comment #11
mudd CreditAttribution: mudd commentedI agree that Bcc might be best when sending to a role, but drupal_mail() seems to not have a bcc field. From the API site:
6-7 drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)
and in mail.inc:
Does anyone think a bcc field should be added to mail.inc and drupal_mail()? (I also don't see any checks against an empty To: field)
'bcc' => $bcc,
BUT, also in drupal_mail() is this section that appears to let a module alter the email via $params. Since the idea above seems crude and would require a drupal core change, perhaps the road to Oz is below (please pardon my newbiness, I'm still learning drupal, PHP and coding methodology)
What would this require? Something in token_actions_mail() that replaces "TO:" with "BCC:" in $message if, say, "private_bcc" is specified in $params? (???)
EDIT: I just noticed this function's already here, but I'm puzzled how to attack this. Do I add somewhere the code to set $params['use_bcc'] = 1 and then in this function check with an IF, and replace all the TO:'s to BCC: in $message['header']?
I did a temp hack on token.module to explode $recipient and then run foreach to send individual emails (yes, a performance hit on large roles, but my user base is still small.)
I'd be nice to also integrate similar code to what jeff.ferrari (awesome name) did for Action email role (#267921: All recipients visible on outgoing mails), such as have a radio button choice when defining the tokenized email action.
Comment #12
mudd CreditAttribution: mudd commentedI'm testing a patch that creates a form checkbox that forces token_actions to send by Bcc: rather than To:. It also checks each user's status and skips them if blocked.
Should I open a "code" or "Token Actions" feature request of type 'needs review' or just attach the patch here?
Note -- I still have two problems...
1) What to put in the TO field. Should it be NO-REPLY@mydomain.com?
2) This is for announcing new-posts. But what if some users don't want to be notified? Will I need a user-page that lets them flag "don't email me on new posts" in the database? (ps, I don't allow access to the 'My account' page)
Comment #13
greggles@mudd - Thanks for your work. Please open a new issue for this.
Comment #14
pounardWhat's the current state of this issue, is this going to be released soon or are you still working on it?
EDIT: I really need this feature, I might help if you want.
Comment #15
mudd CreditAttribution: mudd commentedA small patch for BCC is here: #513934: BCC email option for Token Actions
Comment #16
j0nathan CreditAttribution: j0nathan commentedsubscribing
Comment #17
benoitg CreditAttribution: benoitg commentedsubscribing
Comment #18
AaronBaumanDid anyone else notice that the node tokens don't get tokenized?
I'm using the "Send tokenized e-mail to users of a role" for the event "After saving new content" with the following tokens, none of which get replaced:
[type-name]
[title]
[nid]
Comment #19
AaronBaumanI'm too lazy to roll a patch, but adding this on the first line of
function token_actions_send_email_to_role_action
seems to have fixed it:Comment #20
japanitrat CreditAttribution: japanitrat commentedpatch please :)
Comment #21
vitis CreditAttribution: vitis commentedpatch would be appreciated
Comment #22
Agileware CreditAttribution: Agileware commentedAttached is new_role_email_action3.patch an updated patch file which works for me. Incorporates #1, #19 and the suggestions from #2.
Comment #23
Agileware CreditAttribution: Agileware commentedAnd please review :)
Comment #24
Agileware CreditAttribution: Agileware commentedFixed a bug where the user context was not set for newly registered users.
Updated patch attached.
Comment #25
Agileware CreditAttribution: Agileware commentedRemoved the call to drupal_html_to_text as mentioned in #379948: use of drupal_html_to_text suppresses email-newlines and #317303: Token Actions & Mimemail which was suppressing new line characters and I believe no longer required at all.
Updated patch attached.
Comment #26
netentropy CreditAttribution: netentropy commentedBCC belings in the header, just add it to the header of drupal_mail it works fine
Comment #27
Agileware CreditAttribution: Agileware commentedBCC is not required at all. An individual email is sent to each member of the role. So each user receives a separate email which does not list any other recipients.
Comment #28
Alan.Guggenheim CreditAttribution: Alan.Guggenheim commentedsubscribe
Comment #29
Agileware CreditAttribution: Agileware commentedWe really need someone else to review my latest patch and confirm it's working. Then we can move this request to the next status and hopefully get it committed to the module. Anyone out there able to test the patch?
Comment #30
ddv CreditAttribution: ddv commentedI have a test website (running on Dreamhost) that I use for testing modules prior to deployment on the live site. I can test something, but I'm not a programmer so would need specific instructions on what to do.
Comment #31
flips CreditAttribution: flips commentedHi,
When used the "Send tokenized e-mail" action, it worked great. As I need to "Send tokenized e-mail to users of a role", I patched the Token module with new_role_email_action5.patch (and tried new_role_email_action2.patch) which does what I need but there is still an issue.
The Trigger module does not recognize the new added system action : "Send tokenized e-mail to users of a role" and as there is not other system action, I get a "No available actions for this trigger." message instead of the action select drop-down list.
There are no troubles with other Token actions. Any ideas? Thanks for help.
Comment #32
Alan.Guggenheim CreditAttribution: Alan.Guggenheim commentedAgileware:
I tested your patch and it works great. I created an action and a trigger, and everything worked.
Can you apply your magic to the send tokenized email action? So far, it does not expand any tokens except global!
Would a patch similar to #19 from aaronbauman do the trick?
Thanks
Comment #33
Agileware CreditAttribution: Agileware commented@flips Please use new_role_email_action5.patch as posted on comment #25 - it is the current patch. All others are superseded.
Comment #34
Agileware CreditAttribution: Agileware commented@Alan.Guggenheim thanks for testing.
new_role_email_action5.patch as posted on comment #25 does incorporate the setting of node context as suggested by aaronbauman in #19. Or was it something else you meant? (please explain) :)
Comment #35
Alan.Guggenheim CreditAttribution: Alan.Guggenheim commented@Agileware you are welcome, and it doies work well, I like it and will use it.
But... my initial problem was indeed something else. i found this issue when I was looking for a solution to issue 635570: Tokenized emails do not expand user tokens.
As I saw that you had initially the same issue, but solved it, I am looking for help in fixing the issue in the send_tokenized_email function.
Comment #36
Agileware CreditAttribution: Agileware commented@Alan.Guggenheim are you testing with new_role_email_action5.patch from comment #25 ???
Comment #37
flips CreditAttribution: flips commented@Agileware I tried again (new_role_email_action5.patch as posted on comment #25) and I get the same problem.
I use Trigger and Apply_for_role modules. When I create any action with Token, they are displayed in the Apply_for_role tab of Triggers except the "Send tokenized e-mail to users of a role" one. Under the Users tab of Trigger, this one is displayed.
Could the problem come from the Apply for role module ?
thanks for your help.
Comment #38
nicanorflavier CreditAttribution: nicanorflavier commented@#25 I tested your patch but it's not working, I'm using workflow module, I was able to select the action and configure it, but when I approve and send emails to roles, when I click submit it is giving me a blank white page. Any ideas?
Comment #39
Agileware CreditAttribution: Agileware commented@nickyflavier:
If you are getting a blank white page can you check your apache error log and post the error that is occurring?
Comment #40
dwightaspinwall CreditAttribution: dwightaspinwall commentedPatch in #25 works great for me. Many thanks.
Comment #41
valuebound CreditAttribution: valuebound commented#25: new_role_email_action5.patch queued for re-testing.
Comment #42
5t4rdu5t CreditAttribution: 5t4rdu5t commentedHi,
I've tested patch in #25, corrected 1 typo ($context['recipient'] for $content['recipient']), and added functionality for multiple roles selection.
Any further testing or improvements are welcome!
Comment #44
stinky CreditAttribution: stinky commentedSubscribe
Comment #45
flamingvan CreditAttribution: flamingvan commentedI've taken the #25 patch and done a couple of things with it. I made it into a standalone module (which I put into the modules/token directory). A standalone module is desirable to me because it seems easier to maintain.
More to the point, though, I made the dropdown selection for the role a multiple selection box and modified some of the SQL. This way, you can select multiple roles to which an email will be sent. Also, I added some and/or radio buttons, so you can decide if you want the mail to go to users who are memebers of any of the selected roles ('or') or only users who are members of all of the selected roles ('and').
Would somebody want to test this? Also, my SQL code works but I think it could probably be more concise. Is there a SQL wiz out there who would want to take a crack at it? Here's the relevant section of code:
Comment #46
flamingvan CreditAttribution: flamingvan commentedForgot to include the module
Comment #47
flamingvan CreditAttribution: flamingvan commentedHere's an enhanced version of the module from #47. This one also allows the email sent to be limited by term (for node related actions).
Would anyone mind if I made this into a module project? I'd be happy to give credit to others who wrote the original code that I modified.
Comment #48
valuebound CreditAttribution: valuebound commentedhi,
i am getting information in presenting a node completely as a description where as i want to access all individual variables so as i can display only a few of them.
thanks,
suneel
Comment #49
greggles@valuebound, please don't repurpose an issue to something totally different :/
I think this issue is "won't fix" at this point.
http://drupal.org/project/views_send works really well for this kind of thing.
Comment #50
Agileware CreditAttribution: Agileware commented@greggles what's the reasoning for changing the status to "won't fix" ?
http://drupal.org/project/views_send does not provide this functionality at all and so cannot be used as a replacement for this feature.
Comment #51
gregglesFrom the project page:
Create a view and add at least one column containing E-mail addresses.
[Optional] Expose Views filters to let the user easily build list of recipients using UI.
Create a "Page" display and set the Style to "Bulk Operations".
On "Bulk Operations" Style configuration, under "Selected operations", select Send mass mail (views_send_mail_action).
Save the view, load the page, use exposed filters to build the list, select all or some rows and choose "Send mass mail".
Fill the message form to configure the E-mail. Use tokens to personalize your E-mail. The module provide also row-based tokens, taken from the current row of the view. For example, if the view has a column with the key users_name (the user name) you can use this replacement token [views-send-users_name].
Preview and send the message.
That sounds pretty similar to what this patch did (last I tried it).
Can you point out something that is possible with this patch and not with views_send?
Comment #52
Agileware CreditAttribution: Agileware commentedCan you integrate the Views, Bulk Operations so that it called from the Drupal Action? As that is the feature that this patch provides, sending "Send a tokenized email to users of a role" using a Drupal Action.
Which is trivial to setup and very useful.
Comment #53
dkinzer CreditAttribution: dkinzer commentedsubscribing
Comment #54
gagarine CreditAttribution: gagarine commentedThis module do it https://drupal.org/project/action_email_role .