# Best way to send an email to all users with a certain role?

**URL:** <https://forum.inductiveautomation.com/t/best-way-to-send-an-email-to-all-users-with-a-certain-role/86550>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [February 28, 2024, 9:33pm UTC](https://forum.inductiveautomation.com/t/best-way-to-send-an-email-to-all-users-with-a-certain-role/86550 "2024-02-28T21:33:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [February 28, 2024, 9:33pm UTC](https://forum.inductiveautomation.com/t/best-way-to-send-an-email-to-all-users-with-a-certain-role/86550/1 "2024-02-28T21:33:53Z")

</div>

I'd like to send an html email to all users with a specific role, similarly to how you'd email a report:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/6/569d5d36a36a84dfa562c40f625237c495fcd1a9.png)

The scripting library doesn't seem to have a way to specify an `Address Source` like this for the `system.net.sendEmail` function. Is this function I made the cleanest way to get the email addresses I'm looking for from a Perspective scripting context?

```py
def get_user_emails_with_role(user_source, role):
	emails = []
	for user in system.user.getUsers(user_source):
		if role in user.roles:
			for contact_info in user.contactInfo:
				if contact_info.contactType == 'email':
					emails.append(str(contact_info.value))
	return emails

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 16, 2024, 10:54am UTC](https://forum.inductiveautomation.com/t/best-way-to-send-an-email-to-all-users-with-a-certain-role/86550/3 "2024-04-16T10:54:05Z")

</div>

> [@Otis-Milburnn](#):
>
> Instead of using this way

Your suggestion is totally orthogonal to the OP's question. He is trying to build the list of emails from existing (authentication) resources. Not asking about **delivering** emails.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 16, 2024, 1:30pm UTC](https://forum.inductiveautomation.com/t/best-way-to-send-an-email-to-all-users-with-a-certain-role/86550/4 "2024-04-16T13:30:45Z")

</div>

Closed on April 16, 2024, 1:30pm UTC


