GroupsApp

This class provides access to Google Groups information. It can be used to query information such
as a group's email address, or the list of groups in which the user is a direct member.

Here's an example that shows how many groups the current user is a member of:

```javascript
const groups = GroupsApp.getGroups();
Logger.log(`You belong to ${groups.length} groups.`);
```

### Properties

| Property | Type | Description |
|---|---|---|
| `Role` | `https://developers.google.com/apps-script/reference/groups/role` |   |

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/groups/groups-app#getGroupByEmail(String)` | `https://developers.google.com/apps-script/reference/groups/group` | Retrieves the group having the specified email address. |
| `https://developers.google.com/apps-script/reference/groups/groups-app#getGroups()` | `https://developers.google.com/apps-script/reference/groups/group` | Retrieves all the groups of which you are a direct member (or a pending member). |

## Detailed documentation

### `getGroupByEmail(email)`

Retrieves the group having the specified email address. Throws an exception if the group does
not exist or if you do not have permission to see it.

Here is an example that gets a group by its email address and outputs whether the current
user is a member. Before running, replace the sample email address with a real group's email.

```javascript
const group = GroupsApp.getGroupByEmail('example@googlegroups.com');
const currentUser = Session.getActiveUser();
if (group.hasUser(currentUser)) {
  Logger.log('You are a member of this group.');
} else {
  Logger.log('You are not a member of this group.');
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `email` | `String` | The email address of the group to retrieve. |

#### Return


`https://developers.google.com/apps-script/reference/groups/group` --- The group with the specified email address.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/groups`

*** ** * ** ***

### `getGroups()`

Retrieves all the groups of which you are a direct member (or a pending member). This is an
empty list if you are not in any groups. Throws an exception if the group does not exist or if
you do not have permission to see it.

Here's an example of how to print the email address for every group the user belongs to:

```javascript
function showMyGroups() {
  const groups = GroupsApp.getGroups();
  let str = `You are in ${groups.length} groups: `;
  for (let i = 0; i < groups.length; i++) {
    const group = groups[i];
    str = `${str + group.getEmail()} `;
  }
  Logger.log(str);
}
```
Note that if you are a member of a group, B, which is itself a member of another group, A, then you are *indirectly* subscribed to group A. Even though you receive copies of messages sent to the "parent" group A, you are not actually subscribed to that group.

You can use `https://developers.google.com/apps-script/reference/groups/group#getRole(String)` to determine if you are an existing or pending
member of the returned groups.

#### Return


`https://developers.google.com/apps-script/reference/groups/group` --- The list of groups of which the user is a direct member.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/groups`