# Sending pdf in email

**URL:** <https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726>\
**Category:** Ignition\
**Created:** [February 18, 2015, 10:22pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726 "2015-02-18T22:22:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuartd](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@stuartd](https://forum.inductiveautomation.com/u/stuartd)\
**Post date:** [February 18, 2015, 10:22pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/1 "2015-02-18T22:22:53Z")

</div>

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.

Traceback (most recent call last):

File “event:actionPerformed”, line 17, in

com.inductiveautomation.ignition.client.gateway\_interface.GatewayException: com.inductiveautomation.ignition.client.gateway\_interface.GatewayException: Error sending email.

```
caused by GatewayException: Error sending email.
caused by javax.mail.internet.ParseException: Expected MIME type, got null

```

```auto
#	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.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [February 18, 2015, 11:17pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/2 "2015-02-18T23:17:18Z")

</div>

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

data = event.source.parent.getComponent(‘Report Viewer’)  
bytesPDF = data.getBytesPDF()

# Sends out the email

system.net.sendEmail(smtp=‘[mail.microgreeninc.com](http://mail.microgreeninc.com)’,fromAddr = reporter, subject=header, body=body,html = 0, to = emailList, attachmentNames = [title], attachmentData = [bytesPDF])[/code]

try this

---

<div class="post-metadata">

**Author:** ![stuartd](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@stuartd](https://forum.inductiveautomation.com/u/stuartd)\
**Post date:** [February 18, 2015, 11:32pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/3 "2015-02-18T23:32:17Z")

</div>

i still get that same error message, expected MIME Type, got null. its on the email line.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [February 19, 2015, 12:31am UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/4 "2015-02-19T00:31:19Z")

</div>

will the script send the email if you remove the attachmentname and attachment parameters?

---

<div class="post-metadata">

**Author:** ![stuartd](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@stuartd](https://forum.inductiveautomation.com/u/stuartd)\
**Post date:** [February 19, 2015, 3:40pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/5 "2015-02-19T15:40:03Z")

</div>

yes it is sending the email, if i remove the attachments and title section of it.

---

<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 19, 2015, 3:50pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/6 "2015-02-19T15:50:57Z")

</div>

Can you post the version of Ignition you’re using and the entire stack trace from the error?

---

<div class="post-metadata">

**Author:** ![stuartd](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@stuartd](https://forum.inductiveautomation.com/u/stuartd)\
**Post date:** [February 19, 2015, 4:11pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/7 "2015-02-19T16:11:50Z")

</div>

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)

```

com.inductiveautomation.ignition.client.gateway\_interface.GatewayException: com.inductiveautomation.ignition.client.gateway\_interface.GatewayException: Error sending email.

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

Ignition v7.7.1 (b2014092209)  
Java: Oracle Corporation 1.8.0\_31

Ignition Version 7.7.1 (b2014092209)  
Java Version Oracle Corporation 1.8.0\_11

---

<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 19, 2015, 5:49pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/8 "2015-02-19T17:49:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stuartd](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@stuartd](https://forum.inductiveautomation.com/u/stuartd)\
**Post date:** [February 19, 2015, 6:00pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/9 "2015-02-19T18:00:20Z")

</div>

Old Code

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

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

or how do i add the file extension to that?

---

<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 19, 2015, 6:16pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/10 "2015-02-19T18:16:49Z")

</div>

Use the old code, and add a line that says

```auto
title = title + '.pdf'
```

We just need to change the name of the attachment, not the attachment itself.

---

<div class="post-metadata">

**Author:** ![stuartd](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@stuartd](https://forum.inductiveautomation.com/u/stuartd)\
**Post date:** [February 19, 2015, 6:27pm UTC](https://forum.inductiveautomation.com/t/sending-pdf-in-email/9726/11 "2015-02-19T18:27:50Z")

</div>

awesome. Thank you. that worked perfectly.
