# Execute and distribute unicode problem

**URL:** <https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737>\
**Category:** Ignition\
**Created:** [October 2, 2019, 12:29pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737 "2019-10-02T12:29:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 2, 2019, 12:29pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/1 "2019-10-02T12:29:26Z")

</div>

Hi,  
I send a report by email using run script Schedule. I use executeAndDistribute function in the script.  
When I receive my email, special char appear in the body when my attachment name include special char like “é”,“â”.  
I’ve tried to encode in utf8 but it’s not working.  
Do you have a solution ?

Thanks

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8887588d476d59bd055d7932173bf02e011e75ab.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 2, 2019, 12:49pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/2 "2019-10-02T12:49:11Z")

</div>

I would guess the gateway itself needs to be set to use a utf8 locale.

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [October 2, 2019, 1:00pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/3 "2019-10-02T13:00:34Z")

</div>

Can you compare the binary representations of the letters you received and the letters you wanted? Then you can usually find out from what to what encoding it was converted, and what you have to look for.

I’d like to look it up myself, but I can’t copy-paste from an e-mail, and I can’t type those characters either.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 2, 2019, 1:36pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/4 "2019-10-02T13:36:47Z")

</div>

For example :  
鮥 instead of “éne”  
鴩 instead of “éti”  
鱵 instead of “équ”

How can I set the gateway to UTF8 ?

Thanks

---

<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:** [October 2, 2019, 2:19pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/5 "2019-10-02T14:19:18Z")

</div>

What version of Ignition are you using?

Can you paste the lines of script where you define your attachment name and where you call executeAndDistribute?

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 2, 2019, 2:34pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/6 "2019-10-02T14:34:18Z")

</div>

My code below :

```auto
# On va chercher les id et noms des databases actives
	databases=system.db.runQuery("SELECT id,name,title,station FROM ignition_projects WHERE reportEnable = 1")
	
	body=u"""Madame, Monsieur,\r\rNous vous adressons cet email dans le cadre du monitoring énergétique, qui équipe la résidence en référence (cf. titre de la pièce jointe).\r
		Vous trouverez ci-joint le suivi hebdomadaire de performance du chauffage, pour la période allant du """+str(system.date.format(dataMap['sem4StartDate'], "dd-MM-yyyy"))+""" au """+str(system.date.format(dataMap['sem4EndDate'], "dd-MM-yyyy"))+u""" inclus.\r
		Sur cette période et en fonction des seuils positionnés, des messages d&#39;alerte ont pu être adressés et sont détaillés en 3e page.\r\r
		Restant en vigilance pour la résidence,\r\r
		CET EMAIL EST GÉNÉRÉ AUTOMATIQUEMENT MERCI DE NE PAS Y RÉPONDRE"""
	
	for db in databases:
		
	
		#Pour chaque database on va récupérer les emails des utilisateurs (ignition_user_projects JOIN ignition_user_ci)
		emails=["my@email.fr"]
		
		#heatingState=system.db.runQuery("SELECT valueBool FROM heating_contract WHERE name='heatingState'","test")[0][0]
		heatingState=1
		
		
		#Les variables d'entrées du rapport
		reportParameters = {"projectName":db['title'],"database":db['name'],"station":db['station']}
		subject=db['title']+" - Suivi hebdomadaire de performance du chauffage"
		attachmentName=db['title']+" - Suivi hebdomadaire de performance du chauffage - "+str(system.date.format(system.date.now(), "yyyy-MM-dd"))+".pdf"
		 
		
		if heatingState==1:
			system.report.executeAndDistribute(path="WeekReportV2", project="home", action= "email", parameters=reportParameters ,
			actionSettings = {"to":emails, "smtpServerName":"SMTP", "from":"noreply@email.fr", "subject":subject,"body":body,"attachmentName":attachmentName})

```

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 2, 2019, 2:41pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/7 "2019-10-02T14:41:22Z")

</div>

Using previous code, I receive email below :  
BODY :

```auto
Madame, Monsieur,

Nous vous adressons cet email dans le cadre du monitoring ÃƒÂ©nergÃƒÂ©tique, qui ÃƒÂ©quipe la rÃƒÂ©sidence en rÃƒÂ©fÃƒÂ©rence (cf. titre de la piÃƒÂ¨ce jointe).
Vous trouverez ci-joint le suivi hebdomadaire de performance du chauffage, pour la pÃƒÂ©riode allant du 23-09-2019 au 29-09-2019 inclus.
Sur cette pÃƒÂ©riode et en fonction des seuils positionnÃƒÂ©s, des messages d'alerte ont pu ÃƒÂªtre adressÃƒÂ©s et sont dÃƒÂ©taillÃƒÂ©s en 3e page.

Restant en vigilance pour la rÃƒÂ©sidence,

CET EMAIL EST GÃƒÂ‰NÃƒÂ‰RÃƒÂ‰ AUTOMATIQUEMENT MERCI DE NE PAS Y RÃƒÂ‰PONDRE

```

---

<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:** [October 2, 2019, 2:56pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/8 "2019-10-02T14:56:19Z")

</div>

This sounds exactly like a problem that was fixed in 7.9.5, which is why I was hoping to find out what version you’re using. (FB9167 for other IA employees looking here)

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 3, 2019, 12:42pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/10 "2019-10-03T12:42:46Z")

</div>

My version is 7.9.9 (b2018081621)

---

<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:** [October 3, 2019, 2:45pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/11 "2019-10-03T14:45:49Z")

</div>

Thanks. I’ll see if we can replicate this here

---

<div class="post-metadata">

**Author:** ![apimente](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/apimente/32/4030_2.png) [@apimente](https://forum.inductiveautomation.com/u/apimente)\
**Post date:** [October 8, 2019, 4:11pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/12 "2019-10-08T16:11:24Z")

</div>

Maybe this could help you.

As our native language is spanish, We have problems with special characters often (á, é, ¿, etc).

To solve this problem, in scripting context (python) we put an “u” before the string it self.

For example:

```auto
text1 = u'¿Desea aplicar la confirmación?'

```

The “u” is for “unicode” if i remember correctly  
Hope this help you. Greetings

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 9, 2019, 6:37am UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/13 "2019-10-09T06:37:13Z")

</div>

I’ve already do that. It didn’t work.

---

<div class="post-metadata">

**Author:** ![apimente](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/apimente/32/4030_2.png) [@apimente](https://forum.inductiveautomation.com/u/apimente)\
**Post date:** [October 9, 2019, 12:26pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/14 "2019-10-09T12:26:48Z")

</div>

I’d try to write the email body in execution context (just for testing purposes) and in the script context get the text with “body\_text = event.source.text” or something like that. Then, if the email still shows the special characters like garbage, I think that the problem is with the email generation.

Do you have the same results with this function “system.net.sendEmail”?

---

<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:** [October 9, 2019, 2:06pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/15 "2019-10-09T14:06:53Z")

</div>

@apimente I’ve already replicated the problem and it’s a bug that’s happening with system.report.executeAndDistribute() but is not happening with system.net.sendEmail().

@flavien Until we get a fix, the workaround is use system.report.executeReport() to get the bytes from the report, and attach those to an email you send with system.net.sendEmail()

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 10, 2019, 12:51pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/16 "2019-10-10T12:51:38Z")

</div>

Thanks.  
How can I send my report with system.net.sendEmail function using my variable reportParameters ?  
It’s a dynamic report.

---

<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:** [October 10, 2019, 1:54pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/17 "2019-10-10T13:54:23Z")

</div>

You create your dynamic report using executeReport() [[docs](https://docs.inductiveautomation.com/display/DOC80/system.report.executeReport)], which returns the PDF of the report. Then those bytes are an attachment for your email.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 10, 2019, 3:17pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/18 "2019-10-10T15:17:34Z")

</div>

It works good. My email body use unicode but attachment name and subject still not working.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a029d6ada794d75b30ba85baf356579c700997a5.png)  
The code below

```auto
subject=db['title'].encode('utf-8')+u" - Suivi hebdomadaire de performance du chauffage"
attachmentName=db['title'].encode('utf-8')+u" - Suivi hebdomadaire de performance du chauffage - "+system.date.format(system.date.now(), "yyyy-MM-dd")+u".pdf"

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 10, 2019, 3:29pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/19 "2019-10-10T15:29:57Z")

</div>

Try this:

```auto
subject=unicode(db['title'])+u" - Suivi hebdomadaire de performance du chauffage"
attachmentName=unicode(db['title'])+u" - Suivi hebdomadaire de performance du chauffage - "+system.date.format(system.date.now(), "yyyy-MM-dd")+u".pdf"

```

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [October 14, 2019, 8:28am UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/20 "2019-10-14T08:28:26Z")

</div>

It’s not working. 😢

---

<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:** [October 14, 2019, 2:34pm UTC](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737/21 "2019-10-14T14:34:30Z")

</div>

Since it’s working for me in Ignition 8, now we’re at the hard part of solving this. 🙂

First, let’s try to cut the problem in half. Can you take the same script, but instead of creating an email, make the subject and attachment name show in a label in a Vision window? (Not the script console, which doesn’t always show unicode correctly). That will let us know that the characters are getting to the email correctly.

If the subject and attachment names show correctly in Vision, we want to find out what the gateway sees as the subject when it sends the email. This will take a little work, because we need to trigger a particular logging statement. (Note to self – we should improve the logging here) To do this, send your email to an obviously invalid user, which hopefully your SMTP server will reject rather than just quietly ignore. For example, `user@thing` (ie no `.com` at the end) might trigger this. Set the `SMTP.Manager` logger in the gateway to debug, make sure you use a `retries` value greater than 0, and hopefully we will see a logging statement telling you the email failed. That logging statement will include the subject of the email. You can filter down to that logger in the gateway to make it easier to find.

If the logging statement shows the correct subject, then this unicode failure is probably after the email leaves Ignition. You would need to check the settings on the SMTP server being used. (I’m assuming the email clients receiving the email normally show unicode subjects just fine.)

[Next page](https://forum.inductiveautomation.com/t/execute-and-distribute-unicode-problem/28737.md?page=2)
