# Send Email to current user via system.report.executeAndDistribute

**URL:** <https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675>\
**Category:** Ignition\
**Created:** [November 15, 2020, 8:11pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675 "2020-11-15T20:11:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [November 15, 2020, 8:11pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/1 "2020-11-15T20:11:38Z")

</div>

Good afternoon, all!

I’m working on placing a button on a report form for emailing the data using system.report.executeAndDistribute. This works for a static user, but I can’t seem to locate a method for getting the currently logged-in user’s email address.

Probably simple…but the method doesn’t appear to be well documented in the manuals.

Any help or advice is greatly appreciated!

Thanks,

John

---

<div class="post-metadata">

**Author:** ![rbabcock](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbabcock/32/13425_2.png) [@rbabcock](https://forum.inductiveautomation.com/u/rbabcock)\
**Post date:** [November 16, 2020, 1:59pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/2 "2020-11-16T13:59:38Z")

</div>

I would get the current username using the tag “[System]Client/User/Username” or the script function system.security.getUsername(). Then you can use system.user.getUser to get a user object that has the method getContactInfo().

[https://docs.inductiveautomation.com/display/DOC80/system.user.getUser](https://docs.inductiveautomation.com/display/DOC80/system.user.getUser)

I didn’t test any of this, so if you have any trouble I can pop open a designer and write some code.

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [November 16, 2020, 2:22pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/4 "2020-11-16T14:22:10Z")

</div>

Thanks.

Yes, a code snippet would be helpful. I can get username from system.security.getUsername() just fine, but receive an error for “object has no attribute ‘getContactInfo’” error.

Appreciate the assistance!

---

<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:** [November 16, 2020, 2:31pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/5 "2020-11-16T14:31:33Z")

</div>

> [@jkelleyus](#):
>
> I can get username from system.security.getUsername() just fine, but receive an error for “object has no attribute ‘getContactInfo’” error.

Did you do the step where you take that username and get a User object from `system.user.getUser`?

---

<div class="post-metadata">

**Author:** ![rbabcock](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbabcock/32/13425_2.png) [@rbabcock](https://forum.inductiveautomation.com/u/rbabcock)\
**Post date:** [November 16, 2020, 2:56pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/6 "2020-11-16T14:56:05Z")

</div>

```auto
username = system.security.getUsername()
user = system.user.getUser('default', username)
userContact = user.getContactInfo()
#Some fallback value in case the user doesn't have a registered email
userEmail = "" 
for x in range(len(userContact)):
	if userContact[x].contactType == 'email':
		userEmail = userContact[x].value
		break
print userEmail

```

userContact is a java array of contact objects. I couldn’t think of a better way to iterate over it, but it should usually be a sort list.

---

<div class="post-metadata">

**Author:** ![jkelleyus](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@jkelleyus](https://forum.inductiveautomation.com/u/jkelleyus)\
**Post date:** [November 16, 2020, 3:12pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/7 "2020-11-16T15:12:14Z")

</div>

Thank you again. This worked well!!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 16, 2020, 4:00pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/8 "2020-11-16T16:00:51Z")

</div>

> [@rbabcock](#):
>
> ```auto
> userContact = user.getContactInfo()
> #Some fallback value in case the user doesn't have a registered email
> userEmail = "" 
> for x in range(len(userContact)):
> if userContact[x].contactType == 'email':
> userEmail = userContact[x].value
> break
> print userEmail
> 
> ```

🏌️‍♂️

```python
userEmail = next((ci.value for ci in user.contactInfo if ci.contactType == "email"), "")

```

---

<div class="post-metadata">

**Author:** ![rbabcock](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbabcock/32/13425_2.png) [@rbabcock](https://forum.inductiveautomation.com/u/rbabcock)\
**Post date:** [November 16, 2020, 4:03pm UTC](https://forum.inductiveautomation.com/t/send-email-to-current-user-via-system-report-executeanddistribute/40675/9 "2020-11-16T16:03:22Z")

</div>

That’s perfect. I like to use questions like this as exercises for myself, I’ve learned a lot from it–and from seeing your guys’ golf scores 😉
