Using SMTP e-mail

Ok Carl, Thanks for digging into this one.

How do I send an E-mail without an attachement?? I have tried several different ways and can not figure out how to get the code to work.

Thanks again for your help on this one. You and your team at Inductive Automation are GREAT.

Tyler

Just omit the relevant arguments.

Like this:

system.net.sendEmail("mail.example.com","me@example.com","test email","this is a test",0, ["someone@example.com"])

I’ve isolated the problem. This will be fixed in 7.0.6.

Ok Carl, a couple more questions.

What would be a good programming book to help me with script writting for event handlers inside of Ignition? I hate to keep bothering yall with this problem I am having.

Also… I tried using your code… but I ran back into the first problem I had with AOL… So I changed the code to get around the port issue… but then I ran into the logging into the secured smtp site… so below is the code I am trying to use… and also the error message I am getting.

system.net.sendEmail(“smpt.aol.com:587:tsl”,"myemail@aol.com",“test email”,“this is a test”,0,[“tuttleelectric@aol.com”],[“myusername”],[“mypassword”])

Traceback (innermost last):
File “event:mouseClicked”, line 1, in ?
com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Gateway Error 500: Error sending email.

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:236)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:211)

at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendEmail(GatewayInterface.java:455)

at com.inductiveautomation.factorypmi.application.script.builtin.ClientNetUtilities._sendEmail(ClientNetUtilities.java:94)

at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.sendEmail(AbstractNetUtilities.java:89)

at sun.reflect.GeneratedMethodAccessor77.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)

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

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

at org.python.core.PyObject.invoke(PyObject.java)

at org.python.pycode._pyx35.f$0(<event:mouseClicked>:1)

at org.python.pycode._pyx35.call_function(<event:mouseClicked>)

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

at org.python.core.PyCode.call(PyCode.java)

at org.python.core.Py.runCode(Py.java)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:367)

at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:138)

at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:280)

at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)

at $Proxy0.mouseClicked(Unknown Source)

at java.awt.AWTEventMulticaster.mouseClicked(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.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: javax.mail.internet.ParseException: Expected MIME type, got null

at javax.mail.internet.ContentType.<init>(ContentType.java:91)

at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1271)

at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1008)

at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:415)

at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1287)

at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2072)

at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2040)

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

at com.inductiveautomation.ignition.gateway.script.GatewayNetUtilities.sendEmail(GatewayNetUtilities.java:148)

at com.inductiveautomation.ignition.gateway.servlets.Gateway._sendEmail(Gateway.java:1595)

at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:445)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:85)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(null)

com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Gateway Error 500: Error sending email.

at org.python.core.Py.JavaError(Py.java)
at com.inductiveautomation.factorypmi.application.script.builtin.ClientNetUtilities._sendEmail(ClientNetUtilities.java:97)
at com.inductiveautomation.ignition.common.script.builtin.AbstractNetUtilities.sendEmail(AbstractNetUtilities.java:89)
at sun.reflect.GeneratedMethodAccessor77.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)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:286)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.PyObject.invoke(PyObject.java)
at org.python.pycode._pyx35.f$0(<event:mouseClicked>:1)
at org.python.pycode._pyx35.call_function(<event:mouseClicked>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:367)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:138)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:280)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at $Proxy0.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(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.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)

I've been reading through Dive Into Python to get an understanding of Python fundamentals ... free to download as a PDF, DOC, etc ... so far, so good ...

First of all, you should certainly read the About Python section of our user manual. As far as books go, the last page of that section, Learning More, discusses this.

Your call to sendEmail isn’t valid for a variety of reasons. One is that it is “tls” not “tsl”. Another is that the way you have the code written, it thinks that “myusername” is an attachment name. You need to use keyword invocation. Try something like this:

system.net.sendEmail("smpt.aol.com:587:tls","myemail@aol.com","test email","this is a test",0,["tuttleelectric@aol.com"], username="myusername", password="mypassword")

Ok Carl… I think we have got it now.

My test E-mail worked fine. I have send Test E-Mails to other e-mail accounts and also a TEXT message to my Cell Phone… so I think you have finally gotten me straighten out.

Thanks for the info on Python. I have read some of the information regarding the use of it in Ignition. My problem is my lack of Java , api.net, C#, ect programing. I am use to programing PLC’s and I have programed some in Basic and VB. I usally can figure some things out with examples, but the help file in Ignition, only show an example for using attachements with the SMTP.
I will keep my eyes out for the new revision of Ignition. I will also be glad when you release MODBUS TCP/IP in the OPC-UA. I really like how simple it is to connect to AllenBradly PLCs using OPC-UA and not needing RS-Linx-gateway.

Thanks again,

Tyler

Carl,
What have you figured out on this subject with regards to being able to send an attachment with the email?? We’ve been working with this and it works fine…as long as we don’t fill in the attachment portion. We are using Ign V7.3, Win7 Pro.
Thanks

scott_stc: You’ve resurrected a 1.5yr old thread talking about a bug fixed in 7.0.6 - so you’re going to have to be more specific about the problem you’re having. (A new topic is probably appropriate).