# Issue sending email in script

**URL:** <https://forum.inductiveautomation.com/t/issue-sending-email-in-script/90406>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [May 15, 2024, 8:01am UTC](https://forum.inductiveautomation.com/t/issue-sending-email-in-script/90406 "2024-05-15T08:01:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Bermejo](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Sam\_Bermejo](https://forum.inductiveautomation.com/u/Sam_Bermejo)\
**Post date:** [May 15, 2024, 8:01am UTC](https://forum.inductiveautomation.com/t/issue-sending-email-in-script/90406/1 "2024-05-15T08:01:11Z")

</div>

Hi everyone,

I'm trying to send an email via script. I have configured the smtp profile, and tested it and seems to be working fine, but when I run this part of the code in the script I get an error (see attached images).

File "", line 95, in   
at com.inductiveautomation.ignition.client.script.ClientNetUtilities.\_sendEmail(ClientNetUtilities.java:70)

```
at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.sendEmail(AbstractNetUtilities.java:173)

at jdk.internal.reflect.GeneratedMethodAccessor401.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

```

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot send email without SMTP host, from address and recipient list.

```
at org.python.core.Py.JavaError(Py.java:547)

at com.inductiveautomation.ignition.client.script.ClientNetUtilities._sendEmail(ClientNetUtilities.java:70)

at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.sendEmail(AbstractNetUtilities.java:173)

at jdk.internal.reflect.GeneratedMethodAccessor401.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:552)

at org.python.core.PyObject. __call__ (PyObject.java:400)

at org.python.pycode._pyx965.f$0(<input>:112)

at org.python.pycode._pyx965.call_function(<input>)

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1687)

at org.python.core.Py.exec(Py.java:1731)

at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:611)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:599)

at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

```

Caused by: java.lang.IllegalArgumentException: Cannot send email without SMTP host, from address and recipient list.

```
... 24 more

```

Traceback (most recent call last):  
File "", line 95, in   
at com.inductiveautomation.ignition.client.script.ClientNetUtilities.\_sendEmail(ClientNetUtilities.java:70)

```
at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.sendEmail(AbstractNetUtilities.java:173)

at jdk.internal.reflect.GeneratedMethodAccessor401.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

```

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot send email without SMTP host, from address and recipient list.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/186b7d0d033c30cb8244d4c2756626f3888ca4b6.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/4/54d4bd7e7daa4b0bb87fb048d7c4f24fc56aacb6.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/0/f0fbeed6e81ec0d2efd4ef2fd14dc8bbd4e11b20.png)

Thanks in advance!

---

<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:** [May 15, 2024, 8:28am UTC](https://forum.inductiveautomation.com/t/issue-sending-email-in-script/90406/2 "2024-05-15T08:28:20Z")

</div>

1. I can't see a definite problem but from the manual I see,

> `smtpProfile`  
> If specified, the named SMTP profile defined in the Gateway will be used. If this keyword is present, the smtp, username, and password keywords will be ignored. [optional]

So you can drop the `smtp = smtp1` from sendEmail. Part of the idea here is that you would not hard-code the settings in your script but just point to the SMTP profile. Then if you ever change from [Outlook.com](http://Outlook.com) you just have to edit that gateway's SMTP server setting and all scripts will continue to work.

1. Does smtp2 exactly match the name of the profile?

2. I recommend that you set the from address to something like `scriptname.projectname@servername.companyname.com` and construct this programmatically so that it auto-updates if the project is copied or moved to another server. It will be a big help in debugging quickly if the script goes rogue and your company's email gets blacklisted!

3. Tip: post code - not pictures of code - unless context is important in which case you can post both. See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Sam\_Bermejo](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Sam\_Bermejo](https://forum.inductiveautomation.com/u/Sam_Bermejo)\
**Post date:** [May 15, 2024, 9:05am UTC](https://forum.inductiveautomation.com/t/issue-sending-email-in-script/90406/3 "2024-05-15T09:05:16Z")

</div>

Hi Transistor,

Thanks for your response, You helped me find the error. There was two things I was doing wrong:

1. I was running the script from the script console. The moment I changed it to where I actually wanted the script, it moved to another error.
2. I changed the "bcc" for "to", and it seems to be working now. For now this will do, although I will need to change it in the future.

Thanks
