# Gateway timer script + system.net.sendEmail is giving me SendAsDenied errors

**URL:** <https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [July 5, 2023, 3:34pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945 "2023-07-05T15:34:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [July 5, 2023, 3:34pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945/1 "2023-07-05T15:34:41Z")

</div>

Hi all,

I'm currently working on sending an email through a timer script in the gateway event scripts section. To do this I am using the system.net.sendEmail() function. However, when I attempt to send the email through the SMTP server I've configured I am being presented with the following error:

```auto
com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.252 SendAsDenied

```

From this code:

```auto
body = "<HTML><BODY><H1>This is a big header</H1>"
body += "And this text is <font color='red'>red</font></BODY></HTML>"
recipients = ["...@gmail.com"]
title = "Here is the email"
smtp_server = "Test_Email"
system.net.sendEmail(smtpProfile=smtp_server, fromAddr="...@gmail.com", subject="Here is the email!", body=body, html=1, to=recipients)

```

Note: the emails used in the script are real and used regularly.

I should note that when I use the exact same SMTP server through a pipeline the emails will send as appropriately needed. The issue is I cannot use the pipeline, I need to be able to run these emails through a script. This script does not necessarily need to be in the gateway event scripts either.

Thank you,

Cam

---

<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:** [July 5, 2023, 3:47pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945/2 "2023-07-05T15:47:36Z")

</div>

This is the mail server telling you it won't allow you to "send as" whoever you specified in the `fromAddr` property. For most servers you can't specify any other address than one that matches the credentials you're using to authenticate.

---

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [July 5, 2023, 3:52pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945/3 "2023-07-05T15:52:48Z")

</div>

Ohh, That would make sense. For some reason I thought because that email was predefined in the email server settings I didn't think to use it. Thank you 😃

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 5, 2023, 5:52pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945/4 "2023-07-05T17:52:19Z")

</div>

I recommend getting a service address from your IT department for each Ignition server with a name that's traceable back to your department. e.g., engineering.ìgnition.gateway.01@mycompany.com`. That way if you ever start flooding the system by accident then IT will know who to contact.

---

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [July 5, 2023, 5:53pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945/5 "2023-07-05T17:53:49Z")

</div>

I'll be sure to ask some of the higher IT guys about that. Thank you for the suggestion 😃

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 5, 2023, 5:54pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945/6 "2023-07-05T17:54:38Z")

</div>

Do the same with any other devices such as UPS, etc., that email alarms or status reports. Come up with an appropriate naming convention before you start!

---

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [July 5, 2023, 5:55pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-system-net-sendemail-is-giving-me-sendasdenied-errors/75945/7 "2023-07-05T17:55:23Z")

</div>

Noted 😃 👍
