Hey, so I am trying to set up a report viewer to display a report, then have an option to send it off in an email. I have the report able to be set to a pdf viewer, I can also open it outside of Ignition. but when i try and send the email. i keep getting an error.
caused by GatewayException: Error sending email.
caused by javax.mail.internet.ParseException: Expected MIME type, got null
# The variables
title = event.source.parent.getComponent('Report Viewer').suggestedFilename
header = event.source.parent.getComponent('Report Viewer').suggestedFilename
sender = event.source.parent.noteTaker
reporter = system.db.runScalarQuery("SELECT Email FROM employee_names WHERE Name = '"+sender+"'")
emailList = ['stuart.drollinger@microgreeninc.com']
body = "This the process engineering report for "+sender
# Creates the Attatchment to email out.
data = event.source.parent.getComponent('Report Viewer').bytesPDF
reportSet = system.file.getTempFile('.pdf')
system.file.writeFile(reportSet,data)
report = system.file.readFileAsBytes(reportSet)
# Sends out the email
system.net.sendEmail(smtp='mail.microgreeninc.com',fromAddr = reporter, subject=header, body=body,html = 0, to = emailList, attachmentNames = [title], attachmentData = [report])
Thank you for any help you can offer me, i am kinda stuck at the moment.
title = event.source.parent.getComponent(‘Report Viewer’).suggestedFilename
header = event.source.parent.getComponent(‘Report Viewer’).suggestedFilename
sender = event.source.parent.noteTaker
reporter = system.db.runScalarQuery(“SELECT Email FROM employee_names WHERE Name = '”+sender+"’")
emailList = [‘stuart.drollinger@microgreeninc.com’]
body = "This the process engineering report for "+sender
Creates the Attatchment to email out.
data = event.source.parent.getComponent(‘Report Viewer’)
bytesPDF = data.getBytesPDF()
Traceback (most recent call last):
File “event:actionPerformed”, line 15, in
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:321)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:295)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendEmail(GatewayInterface.java:625)
at com.inductiveautomation.factorypmi.application.script.builtin.ClientNetUtilities._sendEmail(ClientNetUtilities.java:105)
at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.sendEmail(AbstractNetUtilities.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.Py.JavaError(Py.java:495)
at com.inductiveautomation.factorypmi.application.script.builtin.ClientNetUtilities._sendEmail(ClientNetUtilities.java:108)
at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.sendEmail(AbstractNetUtilities.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.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:427)
at org.python.core.PyObject.__call__(PyObject.java:320)
at org.python.pycode._pyx50.f$0(<event:actionPerformed>:15)
at org.python.pycode._pyx50.call_function(<event:actionPerformed>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:568)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:168)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:265)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at com.sun.proxy.$Proxy21.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Error sending email.
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:321)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:295)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendEmail(GatewayInterface.java:625)
at com.inductiveautomation.factorypmi.application.script.builtin.ClientNetUtilities._sendEmail(ClientNetUtilities.java:105)
… 54 more
Caused by: javax.mail.internet.ParseException: Expected MIME type, got null
at javax.mail.internet.ContentType.(ContentType.java:95)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1331)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1021)
at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:419)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1354)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2107)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2075)
at javax.mail.Transport.send(Transport.java:123)
at com.inductiveautomation.ignition.gateway.script.GatewayNetUtilities.sendEmail(GatewayNetUtilities.java:151)
at com.inductiveautomation.ignition.gateway.servlets.Gateway._sendEmail(Gateway.java:968)
at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:393)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:85)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:526)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:568)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1110)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:453)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1044)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:459)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:280)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)
at org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
at java.lang.Thread.run(null)
Derp, this exact same thing tripped me up a couple of weeks ago. This time, I need to make a note for our documentation people.
Attachements are super dependent on having the right file extensions in the name. If you add “.pdf” (without the quotes, obviously) to the end of your filename, you should find all is well.
# The variables
title = event.source.parent.getComponent('Report Viewer').suggestedFilename
header = event.source.parent.getComponent('Report Viewer').suggestedFilename
sender = event.source.parent.noteTaker
reporter = system.db.runScalarQuery("SELECT Email FROM employee_names WHERE Name = '"+sender+"'")
emailList = ['stuart.drollinger@microgreeninc.com']
body = "This the process engineering report for "+sender
# Creates the Attatchment to email out.
bytesPDF = event.source.parent.getComponent('Report Viewer').getBytesPDF()
# Sends out the email
system.net.sendEmail(smtp='mail.microgreeninc.com',fromAddr = reporter, subject=header, body=body,html = 0, to = emailList, attachmentNames = [title], attachmentData = [bytesPDF])
New Code
# The variables
title = event.source.parent.getComponent('Report Viewer').suggestedFilename
header = event.source.parent.getComponent('Report Viewer').suggestedFilename
sender = event.source.parent.noteTaker
reporter = system.db.runScalarQuery("SELECT Email FROM employee_names WHERE Name = '"+sender+"'")
emailList = ['stuart.drollinger@microgreeninc.com']
body = "This the process engineering report for "+sender
# Creates the Attatchment to email out.
bytesPDF = event.source.parent.getComponent('Report Viewer').getBytesPDF()
bytesPDF = bytesPDF + '.pdf'
# Sends out the email
system.net.sendEmail(smtp='mail.microgreeninc.com',fromAddr = reporter, subject=header, body=body,html = 0, to = emailList, attachmentNames = [title], attachmentData = [bytesPDF])