hazey
February 17, 2016, 3:55am
1
Guys I want to email a chart, I have written this script in client event script. It works but I get multiple copies of the email, more than the 2 clients that are open. How can I limit it to one email please?
thx Dennis
[i]if newValue.value == 1:
def chart():
import system
system.nav.openWindow("Main Windows/Processing/Pulp_Trend_Email")
def email():
from javax.imageio import ImageIO
from java.io import ByteArrayOutputStream
window = system.gui.getWindow("Main Windows/Processing/Pulp_Trend_Email")
image = window.rootContainer.getComponent("Easy Chart")
bufferedImg = system.print.createImage(image)
baos = ByteArrayOutputStream()
ImageIO.write(bufferedImg, "PNG", baos)
fileData = baos.toByteArray()
fileName = "history.png"
smtp = "XYZ.local"
sender = "SCADA@XYZ"
subject = "Pulp Trend"
body = "Chart email."
recipients = ["person@XYZ"]
system.net.sendEmail(smtp, sender, subject, body, 0, recipients, [fileName], [fileData])
system.nav.closeWindow("Main Windows/Processing/Pulp_Trend_Email")
system.util.invokeLater(email,4000)
chart()
[/i]
hazey
March 2, 2016, 8:50am
2
Hey guys no takers?
thx hazey
Can you repost your code in a code block so that we can see where the indents are?
Also what is triggering the event script?
Here’s how it was submitted…
[code]if newValue.value == 1:
def chart():
import system
system.nav.openWindow("Main Windows/Processing/Pulp_Trend_Email")
def email():
from javax.imageio import ImageIO
from java.io import ByteArrayOutputStream
window = system.gui.getWindow("Main Windows/Processing/Pulp_Trend_Email")
image = window.rootContainer.getComponent("Easy Chart")
bufferedImg = system.print.createImage(image)
baos = ByteArrayOutputStream()
ImageIO.write(bufferedImg, "PNG", baos)
fileData = baos.toByteArray()
fileName = "history.png"
smtp = "XYZ.local"
sender = "SCADA@XYZ"
subject = "Pulp Trend"
body = "Chart email."
recipients = ["person@XYZ"]
system.net.sendEmail(smtp, sender, subject, body, 0, recipients, [fileName], [fileData])
system.nav.closeWindow("Main Windows/Processing/Pulp_Trend_Email")
system.util.invokeLater(email,4000)
chart()
[/code]
hazey
March 7, 2016, 4:42am
5
Caleb the trigger is just based on time of day, including seconds.
thx
hazey
What happens if you run it in the script editor? Do you get more than one email?
are you running this on a specific client? if so use either the hostname of the machine or ip address in the script so that the email is only sent from that specific machine.