# Email Chart

**URL:** <https://forum.inductiveautomation.com/t/email-chart/11224>\
**Category:** Ignition\
**Created:** [February 17, 2016, 3:55am UTC](https://forum.inductiveautomation.com/t/email-chart/11224 "2016-02-17T03:55:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazey](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@hazey](https://forum.inductiveautomation.com/u/hazey)\
**Post date:** [February 17, 2016, 3:55am UTC](https://forum.inductiveautomation.com/t/email-chart/11224/1 "2016-02-17T03:55:08Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![hazey](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@hazey](https://forum.inductiveautomation.com/u/hazey)\
**Post date:** [March 2, 2016, 8:50am UTC](https://forum.inductiveautomation.com/t/email-chart/11224/2 "2016-03-02T08:50:44Z")

</div>

Hey guys no takers?  
thx hazey

---

<div class="post-metadata">

**Author:** ![Caleb\_Bohon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/caleb_bohon/32/3293_2.png) [@Caleb\_Bohon](https://forum.inductiveautomation.com/u/Caleb_Bohon)\
**Post date:** [March 2, 2016, 12:47pm UTC](https://forum.inductiveautomation.com/t/email-chart/11224/3 "2016-03-02T12:47:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 2, 2016, 1:38pm UTC](https://forum.inductiveautomation.com/t/email-chart/11224/4 "2016-03-02T13:38:21Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![hazey](https://avatars.discourse-cdn.com/v4/letter/h/a587f6/32.png) [@hazey](https://forum.inductiveautomation.com/u/hazey)\
**Post date:** [March 7, 2016, 4:42am UTC](https://forum.inductiveautomation.com/t/email-chart/11224/5 "2016-03-07T04:42:22Z")

</div>

Caleb the trigger is just based on time of day, including seconds.

thx  
hazey

---

<div class="post-metadata">

**Author:** ![Caleb\_Bohon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/caleb_bohon/32/3293_2.png) [@Caleb\_Bohon](https://forum.inductiveautomation.com/u/Caleb_Bohon)\
**Post date:** [March 7, 2016, 2:06pm UTC](https://forum.inductiveautomation.com/t/email-chart/11224/6 "2016-03-07T14:06:12Z")

</div>

What happens if you run it in the script editor? Do you get more than one email?

---

<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:** [March 7, 2016, 3:54pm UTC](https://forum.inductiveautomation.com/t/email-chart/11224/7 "2016-03-07T15:54:03Z")

</div>

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.
