Gmail node subject text encoding issue

Describe the problem/error/question

Hi,

I’m facing an encoding problem while sending email with gmail node for every char with and accent (é,à,ô,î…). I noticed that this problem doesn’t occurs when i’m directly writing inside the node “subject” input but only when i pass this subject as an expression (from a code node, and before, from a datatable). On the n8n webUI, i do not encounter this encoding problem (even in the datatable).
It looks like a double UTF-8 encoding issue but i can’t resolve it, even while using JS tricks like unescape(), decodeURI() or even with replacing in the string with something like .replace(/é/g, ‘é’), both from the gmail node or the code block before.

Note: this encoding problem only occurs on email subject, not on the html content.
Thanks in advance for any help on this topic

What is the error message (if any)?

No error messaage but email subject has encoding issue with “é”,”è”,”à”,”ç”,”ô”…

Please share your workflow

Share the output returned by the last node

In web preview mode, output is correct. But when i receive the email. Subject containing a french word like “Actualités” appears like “Actualités”

Information on your n8n setup

  • **n8n version: latest (**2.12.3)
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker (auto-hosted)
  • Operating system: Ubuntu LTS on host - default image on container

Hi @codeyourweb Welcome! i have encountered this same issue with that subject field, i have used n8n-nodes-text-manipulation community node and that fixed my issue as i added that node before the gmail node with decode html legacy to send exactly what i wanted, but you can even try using code node i have not personally tried using that but code node with normalizing the string can be a fix like:

// Force correct UTF-8 decoding if the string is double-encoded
const subject = Buffer.from(yourSubjectString, 'latin1').toString('utf8');
return [{ json: { subject } }];

Although this can sometimes be lossy in some cases but it is worth giving a try, using replaceSpecialChars() is good but it will eventually loose the meaning in some word cases. Let me know how that code node and community node performs in your use case.

Hi, Thank you for this answer. I’ve tried with Buffer on my previous tests but i didn’t worked. I used n8n-nodes-text-manipulation and it works perfectly with these parameters: