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 ?
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.
# 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'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})
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)
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”?
@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()
It works good. My email body use unicode but attachment name and subject still not working.
The code below
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"
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"
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.)