# Running Gateway Scripts Query

**URL:** <https://forum.inductiveautomation.com/t/running-gateway-scripts-query/106746>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [May 27, 2025, 6:46pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts-query/106746 "2025-05-27T18:46:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raees.khan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/raees.khan/32/76218_2.png) [@raees.khan](https://forum.inductiveautomation.com/u/raees.khan)\
**Post date:** [May 27, 2025, 6:46pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts-query/106746/1 "2025-05-27T18:46:39Z")

</div>

Hello,

I have a timed gateway event script that does not seem to be running and I do not know why  
Here is the code:

```python
def runAction(self, event):
	subject = "Alert: Long Session Detected"
	body = "Testing"

    system.util.getLogger("Session Email Script").info("Email sent successfully")

	recipient = ["demo@email.com"]
	smtpProfile = "alertSmtp" # This matches the email profile in the Gateway

	try:
		system.net.sendEmail(
		smtpProfile=smtpProfile, 
		fromAddr="alert@station.com", 
		subject=subject, 
		body=body, 
		to=recipient
		)
		system.util.getLogger("Session Email Script").info("Email sent successfully")
	except Exception as e:
		system.util.getLogger("Session Email Script").info("Failed to send Email: %e" % str(e))

```

What could be the reason the code is not bring executed in the gateway?

Thank You

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 27, 2025, 6:50pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts-query/106746/2 "2025-05-27T18:50:20Z")

</div>

There is a gateway scripts page in the gateway web interface. It should show you when a gateway script executes and any errors if it fails. `Status→Gateway Scripts`

---

<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:** [May 27, 2025, 7:06pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts-query/106746/3 "2025-05-27T19:06:01Z")

</div>

See this topic:

> [@System.net.sendmail not getting trapped by try except](https://forum.inductiveautomation.com/t/system-net-sendmail-not-getting-trapped-by-try-except/106609):
>
> I have the following code and when I get an error it does not do the except, it crashes and dumps the error message into the wrapper log file. In this case it was an invalid email address, I am now validating every email address, but if I miss something in the error checking, or a server error occurs, or anything else, the script crashes and no further processing occurs and the user has no idea that the email was not sent (doesn't execute WriteToQCAuditFile). Is there any way to trap ALL error…

---

<div class="post-metadata">

**Author:** ![raees.khan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/raees.khan/32/76218_2.png) [@raees.khan](https://forum.inductiveautomation.com/u/raees.khan)\
**Post date:** [May 27, 2025, 10:48pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts-query/106746/4 "2025-05-27T22:48:05Z")

</div>

I managed to fix the issue. I was developing the timed gateway event script in a project that I used to inherit views instead of the main project.

Once I developed the gateway scripts in the main project, I was able to see it in the Gateway Script page in the Gateway and the code was executing at the rate I set.
