# Exclude certain email sub-domains from automatic group membership

**URL:** https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212
**Category:** Feature
**Tags:** groups
**Created:** [April 26, 2018, 11:51am UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212 "2018-04-26T11:51:14Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [April 26, 2018, 11:51am UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/1 "2018-04-26T11:51:14Z")

</div>

I’m looking at the automatic group membership setting (in group settings). It states

> Users who register with an email domain that exactly matches one in this list will be automatically added to this group:

Am I correct in assuming that entering `bar.com` will also trigger membership for emails ending in `foo.bar.com`? Or is the word “exactly” meant to state that exactly that is not the case?

Assuming that my assumption is correct, I’m looking for a solution for the following:

Goal: All employees (and only employees) of a university should automatically get membership in the group employees .

Strategy: Use the university’s domain `uni.edu` in the above setting to automatically assign membership

Problem: Student email-addresses also end in `uni.edu` but they should not get access to the group.

Possible solution: If I could exclude `student.uni.edu` from getting automatic membership, that should work, but I believe this is currently not possible. Or am I missing something? Any smart workarounds?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [April 26, 2018, 12:11pm UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/2 "2018-04-26T12:11:42Z")

</div>

It already works that way.

It matches the full domain after the @, so when you configure your group to automatically assign membership for `uni.edu` it will match `foo@uni.edu`, but not `foo@student.uni.edu`

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [April 26, 2018, 12:18pm UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/3 "2018-04-26T12:18:50Z")

</div>

> [@gerhard](#):
>
> It already works that way.

Ah, okay, then my assumption was wrong. But then my issue is another one: I need some sort of catch-all for `*.uni.edu` because it is impossible to predict the exact sub-domain of an employees email-address. Some have `uni.edu`, but many have various subdomains like `sociology.uni.edu`, depending on their departmental affiliation or what they chose as their main affiliation or whatever other determinants there may be.

Is there any way to catch all of these without being able to provide a full list of all possible sub-domains?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [April 26, 2018, 12:45pm UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/4 "2018-04-26T12:45:00Z")

</div>

> [@tophee](#):
>
> Is there any way to catch all of these without being able to provide a full list of all possible sub-domains?

Unfortunately that’s currently not possible.

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [June 1, 2018, 11:15am UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/5 "2018-06-01T11:15:23Z")

</div>

What would it take to create a plugin/PR that would make `*.uni.edu` work, i.e. that it would catch all users with an email address ending in `uni.edu`, regardless of whether there is a subdomain or not? My hunch is that it should be pretty easy (read: I might be able to do it), but maybe I’m wrong?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [June 1, 2018, 12:52pm UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/6 "2018-06-01T12:52:21Z")

</div>

Sure, I think a PR that adds support for wildcards would be fine.

Search for `automatic_membership_email_domains` in the code if you want to give this a try. It’s used in a couple of files.

---

<div class="post-metadata">

### Author: ![JoelZaslofsky](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joelzaslofsky/32/158556_2.png) [@JoelZaslofsky](https://meta.discourse.org/u/JoelZaslofsky)
#### Post date: [March 19, 2020, 9:35pm UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/7 "2020-03-19T21:35:59Z")

</div>

> [@gerhard](#):
>
> I think a PR that adds support for wildcards [in the “Users who register with an email domain that exactly matches one in this list will be automatically added to this group:” field when creating a new group] would be fine.

Gerhard, do you know if a PR ever got created for this? I’d like an easy front-end administration way so that _every_ new Discourse ID that gets created is assigned to a specific group.

For example, I’d like to just put a wildcard character of \* in the “Users who register with an email domain that exactly matches one in this list will be automatically added to this group:” field and know that all new users join the group, regardless of their email address.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 19, 2020, 10:23pm UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/8 "2020-03-19T22:23:55Z")

</div>

What is the point, exactly, of a group that contains _all_ users? 🤔

---

<div class="post-metadata">

### Author: ![ChristopherMcEwan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/christophermcewan/32/41465_2.png) [@ChristopherMcEwan](https://meta.discourse.org/u/ChristopherMcEwan)
#### Post date: [March 20, 2020, 2:35am UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/9 "2020-03-20T02:35:57Z")

</div>

I think the intention is that there would be multiple groups, each one associated with a different domain. All users who match a specific domain would be allocated to that group.

A use case would be to automatically create groups associated with a specific organisation (and knowing that the group members are exclusively from that organisation). This would be useful in my community.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 20, 2020, 4:03am UTC](https://meta.discourse.org/t/exclude-certain-email-sub-domains-from-automatic-group-membership/86212/10 "2020-03-20T04:03:21Z")

</div>

No, note specifically what was said:

> [@JoelZaslofsky](#):
>
> I’d like to just put a wildcard character of \* in the “Users who register with an email domain that exactly matches one in this list will be automatically added to this group:” field and know that **all new users join the group, regardless of their email address.**

I’ve bolded the relevant text.
