exportAndDistribute Report with Gmail

I’m working on creating a script that will send a report when a batch and/or job number is completed and I want to send it through an email. I’ve gotten the base report creation down with local file saves and I’m transitioning it to the email distribution and I’m having some issues with my email actionSettings configuration and getting log messages saying “Error in sending email for report config Email” with the detailed log below.
I’ve set up an SMTP profile on my gateway, image below, and I’d like some further assistance on how to set up email delivery because I know things can get weird with configuring mail servers and being authorized to do so with Gmail.
Also is there any way I can assign a fileName to the report like when you’re doing a local save?

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 25; timeout 10000

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2053)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)

at javax.mail.Service.connect(Service.java:386)

at javax.mail.Service.connect(Service.java:245)

at javax.mail.Service.connect(Service.java:194)

at javax.mail.Transport.send0(Transport.java:253)

at javax.mail.Transport.send(Transport.java:124)

at com.inductiveautomation.ignition.gateway.smtp.SmtpManagerImpl.sendMailWithRetries(SmtpManagerImpl.java:237)

at com.inductiveautomation.ignition.gateway.smtp.SmtpManagerImpl.sendEmail(SmtpManagerImpl.java:202)

at com.inductiveautomation.reporting.gateway.actions.EmailAction.perform(EmailAction.java:143)

at com.inductiveautomation.reporting.gateway.actions.EmailAction.perform(EmailAction.java:320)

at com.inductiveautomation.reporting.gateway.scripting.GatewayScriptingFunctions.executeAndDistribute(GatewayScriptingFunctions.java:326)

at com.inductiveautomation.reporting.common.scripting.ReportScriptingFunctionsPyWrapper.executeAndDistribute(ReportScriptingFunctionsPyWrapper.java:74)

at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

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

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

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

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

at org.python.pycode._pyx59.valueChanged$1(:17)

at org.python.pycode._pyx59.call_function()

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

at org.python.core.PyBaseCode.call(PyBaseCode.java:301)

at org.python.core.PyFunction.function___call__(PyFunction.java:376)

at org.python.core.PyFunction.__call__(PyFunction.java:371)

at org.python.core.PyFunction.__call__(PyFunction.java:361)

at org.python.core.PyFunction.__call__(PyFunction.java:356)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:649)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$FunctionInvokerImpl.run(TagScriptManager.java:493)

at com.inductiveautomation.ignition.common.sqltags.scripts.AbstractTagScript.invoke(AbstractTagScript.java:33)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$Task.invoke(TagScriptManager.java:442)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$TagScriptDispatcher.run(TagScriptManager.java:405)

at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:518)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

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

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

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

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

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

Caused by: java.net.SocketTimeoutException: connect timed out

at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:310)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
	settings={"to":["~~~@gmail.com"], "smtpServerName":"test", "from":"s_petrarca@my.uri.edu~powered by Gmail~", "subject":"Test Report"}
	system.report.executeAndDistribute(path="C-num Report", project="Line5", action="email", actionSettings = settings)

Instead of using your regular password, generate AppPassword for non-google applications.

2 Likes

Ramakrishna.K is correct – we’ve used gmail a lot in our testing, and we’ve always had to set up the app password. https://support.google.com/accounts/answer/185833?hl=en

1 Like

But also note that AppPassword support is ending in less than a year.

If your company operates its own mail servers, consider using them directly.

1 Like

Ouch, but good to know. Thanks, Phil.

That is rough but this is mainly for testing purposes and to be later implemented within their systems with their mail servers. I’ll try the app password for now and see where that gets me.

1 Like

I’ve switched over the the App Password from Gmail and made some more adjustments to my script but I’m still getting errors with sending email. The university I’m working with doesn’t allow App Passwords so I’ve switched to a personal account.

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 25; timeout 10000

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2053)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)

at javax.mail.Service.connect(Service.java:386)

at javax.mail.Service.connect(Service.java:245)

at javax.mail.Service.connect(Service.java:194)

at javax.mail.Transport.send0(Transport.java:253)

at javax.mail.Transport.send(Transport.java:124)

at com.inductiveautomation.ignition.gateway.smtp.SmtpManagerImpl.sendMailWithRetries(SmtpManagerImpl.java:237)

at com.inductiveautomation.ignition.gateway.smtp.SmtpManagerImpl.sendEmail(SmtpManagerImpl.java:202)

at com.inductiveautomation.reporting.gateway.actions.EmailAction.perform(EmailAction.java:143)

at com.inductiveautomation.reporting.gateway.actions.EmailAction.perform(EmailAction.java:320)

at com.inductiveautomation.reporting.gateway.scripting.GatewayScriptingFunctions.executeAndDistribute(GatewayScriptingFunctions.java:326)

at com.inductiveautomation.reporting.common.scripting.ReportScriptingFunctionsPyWrapper.executeAndDistribute(ReportScriptingFunctionsPyWrapper.java:74)

at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

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

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

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

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

at org.python.pycode._pyx63.valueChanged$1(:17)

at org.python.pycode._pyx63.call_function()

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

at org.python.core.PyBaseCode.call(PyBaseCode.java:301)

at org.python.core.PyFunction.function___call__(PyFunction.java:376)

at org.python.core.PyFunction.__call__(PyFunction.java:371)

at org.python.core.PyFunction.__call__(PyFunction.java:361)

at org.python.core.PyFunction.__call__(PyFunction.java:356)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:649)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$FunctionInvokerImpl.run(TagScriptManager.java:493)

at com.inductiveautomation.ignition.common.sqltags.scripts.AbstractTagScript.invoke(AbstractTagScript.java:33)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$Task.invoke(TagScriptManager.java:442)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$TagScriptDispatcher.run(TagScriptManager.java:405)

at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:518)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

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

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

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

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

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

Caused by: java.net.SocketTimeoutException: connect timed out

at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:310)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
	settings={"to":["~~~@gmail.com"], "smtpServerName":"test", "from":"~~~@gmail.com", "subject":"Test Report", "attachmentName":title % (stats[0].value, stats[1].value, rStart, rEnd)}
	system.report.executeAndDistribute(path="C-num Report", project="Line5", action="email", actionSettings = settings)

Try with port 587 and STARTTLS.

1 Like

That did it. I successfully sent and received the email. Thanks for the help.:+1:

1 Like