# exportAndDistribute Report with Gmail

**URL:** <https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527>\
**Category:** Ignition\
**Tags:** scripting, ignition79\
**Created:** [February 24, 2020, 1:13am UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527 "2020-02-24T01:13:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![s\_petrarca](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@s\_petrarca](https://forum.inductiveautomation.com/u/s_petrarca)\
**Post date:** [February 24, 2020, 1:13am UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/1 "2020-02-24T01:13:35Z")

</div>

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?

```auto
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)

```

```auto
	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)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d6e4253f75871eb27571b2b240ca5affe8c0d17d.png)

---

<div class="post-metadata">

**Author:** ![Ramakrishna.K](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Ramakrishna.K](https://forum.inductiveautomation.com/u/Ramakrishna.K)\
**Post date:** [February 24, 2020, 5:33am UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/3 "2020-02-24T05:33:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [February 24, 2020, 3:29pm UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/4 "2020-02-24T15:29:49Z")

</div>

[Ramakrishna.K](http://forum.inductiveautomation.com/u/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](https://support.google.com/accounts/answer/185833?hl=en)

---

<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:** [February 24, 2020, 3:34pm UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/5 "2020-02-24T15:34:58Z")

</div>

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

> [@Gmail Removing Support for 'Less Secure Apps'](http://forum.inductiveautomation.com/t/gmail-removing-support-for-less-secure-apps/31238):
>
> I am currently using G-Suite/Gmail to send alarm notifications. In order to make this work, I had to enable “Less Secure Apps” in Google settings. I recently received an email from Google that says: “Starting February 15, 2021, G Suite accounts will only allow access to apps using OAuth. Password-based access will no longer be supported.” It goes on to say “Access to LSAs will be turned off for all G Suite accounts”. Is this something we should be worried about? Is Ignition planning on add…

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

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [February 24, 2020, 3:50pm UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/6 "2020-02-24T15:50:29Z")

</div>

Ouch, but good to know. Thanks, Phil.

---

<div class="post-metadata">

**Author:** ![s\_petrarca](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@s\_petrarca](https://forum.inductiveautomation.com/u/s_petrarca)\
**Post date:** [February 24, 2020, 4:02pm UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/7 "2020-02-24T16:02:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![s\_petrarca](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@s\_petrarca](https://forum.inductiveautomation.com/u/s_petrarca)\
**Post date:** [February 24, 2020, 7:30pm UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/8 "2020-02-24T19:30:52Z")

</div>

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.

```auto
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)

```

```auto
	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)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5d3efb463050a8cbab7b29ed8db223ac1f58e69a.png)

---

<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:** [February 24, 2020, 7:34pm UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/9 "2020-02-24T19:34:50Z")

</div>

Try with port 587 and STARTTLS.

---

<div class="post-metadata">

**Author:** ![s\_petrarca](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@s\_petrarca](https://forum.inductiveautomation.com/u/s_petrarca)\
**Post date:** [February 24, 2020, 7:49pm UTC](https://forum.inductiveautomation.com/t/exportanddistribute-report-with-gmail/32527/10 "2020-02-24T19:49:13Z")

</div>

That did it. I successfully sent and received the email. Thanks for the help.👍
