While copying the string to email "Error: Email validation failed error: "Email body is comprised of invalid HTML" due to "<test text>" mentioned in the variable

Saurabh Singh5
Tera Expert

Hi,

we have a catalog item which pick up a set of emails (Variable is string field) example sample,sample <sample.servicenow.com> the tag once used if i am sending an email via the Flow designer the email puts and error as Error: Email validation failed error: "Email body is comprised of invalid HTML"  Once i remove the tag manually and give it as sample.service-now.com it starts working, Is there any way we can stop this error from happening.

Can we replace the < tags> with blank spaces i am not sure would be helpful if some one could help with this i am moving towards a before business rule but not getting ideas on where to start from.

 

Regards,

Saurabh Singh

 

1 ACCEPTED SOLUTION

arielgritti
Mega Sage

Hi @Saurabh Singh5 

You can create an "action" with an input string, a step to remove HTML tags and an output string.

In "my case" I only need to remove "<>" characters. My issue is with a string containing <a@a.com> or <sip:xxxxx>

 

This is the step into the action

(function execute(inputs, outputs) {  
// Input variable
var htmlString = inputs.text_IN;

// Remove HTML tags using regular expressions
var cleanString = htmlString.replace(/[<>]/g, '');

// Output variable
outputs.text_out = cleanString;
  
})(inputs, outputs);

 

Please mark helpful or correct if I helped you.
This action will help other members with similar issues to find a solution.
Thanks
Ariel

View solution in original post

4 REPLIES 4

Paul Mozingo
Tera Contributor

Realizing this is an old post, but for anyone looking for a solution and finding this as I did - we ended up changing our variable type to HTML instead of multi-line string. When using the HTML variable type, SN seemed to know what to do in composing the email.

Wayne Miller
Tera Guru

We're also getting this.  As we paste some emails (including the header) into Work Notes, we have a flow that adds the latest work note to a "Send Email" and this always Errors with the above error.

 

I've seen solutions whereby we need to add Regex to strip the bad HTML from the email body, but I'm unsure of where to add this.

Community Alums
Not applicable

I am looking for a solution too. i see that using regex to strip HTML  tag may help.. but i don't know  where to put it...If anyone have a solution.

arielgritti
Mega Sage

Hi @Saurabh Singh5 

You can create an "action" with an input string, a step to remove HTML tags and an output string.

In "my case" I only need to remove "<>" characters. My issue is with a string containing <a@a.com> or <sip:xxxxx>

 

This is the step into the action

(function execute(inputs, outputs) {  
// Input variable
var htmlString = inputs.text_IN;

// Remove HTML tags using regular expressions
var cleanString = htmlString.replace(/[<>]/g, '');

// Output variable
outputs.text_out = cleanString;
  
})(inputs, outputs);

 

Please mark helpful or correct if I helped you.
This action will help other members with similar issues to find a solution.
Thanks
Ariel