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.
Hi,
I am currently using the Broadcast facility offered by og_notifications, and I would like to be able to have the "From" address be filled in with the current user's address. Currently all the broadcast messages have the site address in their "From" field. Is there an way to set this? (or at least can you point me to some hook to implement/function to theme to change the From address of the broadcast message?)
Thanks.
Comment | File | Size | Author |
---|---|---|---|
#9 | og-broadcast.patch | 1.85 KB | Jody Lynn |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedhook_mail_alter is the code for this.
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedActually that sounds like a bug. Might be fixed in 2.x branch.
Comment #3
katiusha CreditAttribution: katiusha commentedI've installed the latest dev releases for the og(6.x-2.x-dev, May 6th), messaging(6.x-2.x-dev, April 30th) and notifications(6.x-2.x-dev, April 30th) modules, and this problem is still there, the broadcast message is sent with the site's mail as a "From" address rather than the email of the currently logged in user.
Comment #4
Jody LynnThe problem seems to be that notifications_lite_send doesn't keep track of a sender. We may need to push this as a feature request to notifications.
Comment #5
Rosamunda CreditAttribution: Rosamunda commentedAs this wasn´t added to the notifications queue, I´ll change the project, to avoid creating duplicate issue posts.
Comment #6
Jose Reyero CreditAttribution: Jose Reyero commentedI thought og handled 'From' field for messages it sends. Please clarify whether this is a bug, feature request, or what.
Comment #7
Jody LynnHi Jose
og_broadcast_form_submit creates a message with a 'from' field and og_notifications_og then uses notifications_lite_send but notifications_lite_send doesn't seem to take a parameter for 'from'. I'm not sure if og is using notifications incorrectly or if notifications_lite could need adjustment.
Comment #8
Jody LynnComment #9
Jody LynnSending this back to og with a patch. I now think it's og's bug because notifications is meant to handle system emails and does not worry about custom From: fields.
This patch uses standard drupal mail for og broadcast emails and includes the corrent 'from' value.
Comment #10
Zen CreditAttribution: Zen commentedThe patch effectively is self-defeating as the idea of using notifications-lite is to allow the use of the main notifications module (and drupal_mail as the fall-back) in delivering the message.
I now think it's og's bug because notifications is meant to handle system emails and does not worry about custom From: fields. Is there an issue where the notifications devs allude to this?
IIRC, this was working fine at one point. If it's not working now, it's an OGN/notifications bug.
-K
Comment #11
Jody LynnYeah, the patch is really just a cheap workaround.
Comment #12
dugh CreditAttribution: dugh commentedI tried the patch but emails are still coming from the sitewide email address for broadcasts.
Tried it with and without the mimemail module enabled.
Comment #13
msielskiMoshe,
Using hook_mail_alter seems like the most appropriate short-term fix but I am having trouble identifying just broadcast messages within that hook.
I setup a simple module providing hook_mail_alter for this purpose, and I do see the messages with it. However, I am not sure there is a way to target broadcast messages independent of all messages sent with the Notifications module.
The $message['id'] is "messaging_message-notifications" which I think is shared by everything that Notifications sends. I tried to attempt a small hack of og_notifications.module to add an identifying param to the notifications_lite_send call in og_notifications_og, however for some reason the only param I get in my hook_mail_alter is the 'from' param.
I am resorting to doing text matching against the $message['body'] for text specific to the broadcast template. If found I'll then adjust the from field and corresponding headers. This just feels really ugly and is prone to break as soon as our template changes.
Since you suggested h_m_a, is there a good way of using it to target just these broadcast messages?
Thanks,
Matt
Comment #14
abaddon CreditAttribution: abaddon commentedi found the issue, its a bug in notifications light, which OG uses to send notifications, im changing the issue there
first you need to configure notifications at admin/messaging/notifications
Notifications Sender: Full user data (User name and available user information)
then apply the change below (patch was run on an older version, basically you need to comment out the uid field in the $event array in notifications_lite_add_to_queue(), in file notifications/notifications_lite/notifications_lite.module)
leaving uid out will auto-set its value to the current's user uid notifications_event(), and use it as the sender as it should, the above configuring decides this..
p.s. this covers only the first if in notifications_lite_send(), the 'notifications' case which is what i had to fix
for 'messaging' you need to set something like $message['params']['mail']['from'] = 'User Name '; to cover both cases where mimemail and drupal_mail are used.. drupal_mail uses only this value, where as mimemail i think supports building it from the user account, kinda inconsistent, see messaging_mail_prepare() in messaging/messaging.mail.inc, and messaging/messaging_mail/messaging_mail.module and messaging/messaging_mime_mail/messaging_mime_mail.module for more info.. i didnt look into phpmailer, so theres yet another choice
and for the last if, where drupal mail is used directly, it just needs the $from parameter set, same format as $message['params']['mail']['from'] so that can be reused.. i guess a global $user and assemble name and email, use the theme_(?) call to account for realname module (i dont have time to fix and check this now.. sorry)
hope someone will find this useful
Comment #15
abaddon CreditAttribution: abaddon commentedComment #16
jpamental CreditAttribution: jpamental commentedI just want to comment that the fix in #14 worked perfectly - but be careful to ONLY comment out the line on #85! Seems like a Notifications module issue in not respecting the declared 'from' address from OG.
Comment #17
bsandor CreditAttribution: bsandor commentedI don't want my Group admins setting an email address. Absolutely bad idea. They can set anything they want. Not good.
Comment #18
sidharthapyes #14 works but is this a good approach to do ?