Skip to main content
4 of 6
added 283 characters in body
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

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 and with group type Class.

  1. 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 ...

Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182