Issue sending email in script

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

Thanks in advance!

  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 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.

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