0

I am using the Group module on a Drupal 7 project. I would like the system to send an email notification once a new member is invited.

I'm assuming I could use the Rules module to perform this task, but so far my new rule configurations for this task is not working.

Has anyone experienced this issue and resolved it? If so please share your steps on how you achieved this.

0

The Group module, out of the box, does not seem to send any eMail notifications to some user who got invited to join some group. Note however that a special Drupal message is shown right after an invited user performs a login to the site (too bad if the invited user never performs a login ...). Here is a sample of such message (which includes a link to relative path /user/uid/group/invite):

You have pending group invitations. Visit your profile to see them.

However, since Group is entirely entity based, it's a piece of cake to use Rules for creating such eMails. The clue to do so, is related to the creation of a new group membership, and which corresponds to Rules Event "After saving a new group membership*". This Rules Event is one of the events added by the Group module, located with 'Rules group' (don't get confused ...) "Group membership". However, a Group membership also has a status, which can be any of these:

  • Active
  • Requested
  • Blocked
  • Invited

With the above in mind, you can create a rather basic rule to do what you're asking for. Just use the Rules UI to import the rule below (in Rules export format) in your own site:

{ "rules_notification_about_new_group_invitation" : {
    "LABEL" : "Notification about new group invitation",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "group" ],
    "ON" : { "group_membership_insert" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "group-membership:status" ], "value" : "invited" } }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "The user with name [group-membership:user] just got invited by [group-membership:invited-by:name] to join the group named [group-membership:group:title] (with group type [group-membership:group:group-type:label])." } },
      { "mail" : {
          "to" : [ "group-membership:user:mail" ],
          "subject" : "You\u0027re invited by [group-membership:invited-by:name] to join the group \u0022[group-membership:group:title]\u0022",
          "message" : "You\u0027re invited by [group-membership:invited-by:name] to join the group named [group-membership:group:title] (with group type [group-membership:group:group-type:label]).",
          "from" : [ "group-membership:invited-by:mail" ],
          "language" : [ "" ]
        }
      }
    ]
  }
}

Some more details about the Rules Actions in this rule:

  1. show a Drupal message, each time a user is invited to join some group, similar to this sample message (which also shows various Group related tokens you can take advantage of, such as the name and type of the group):

    The user with name Demo.User just got invited by Pierre.Vriens to join the group named Using the Answers module (with group type Class).

  2. Create an appropriate eMail, using the various (relevant) tokens, e.g. the eMail Id of the user who performs the invite (= from), and the user that is invited (=to).

Note that for some user who is "added" to a group (instead of "invited") by an authorized user to do so, such message will not be shown. That's because of the Rules Condition included: the status for the selected group is not "Invited" in that case, instead the status will be "Active".

BTW, if you'd be willing (and able) to also use the Message module, you could add an extra Rules Action to create an appropriate Message entity (like a custom log record) also. And if you'd then use the Views module to create a custom view of such Messages, you'd have a perfect audit trail of who invited who for any of your groups ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.