0

I have a string which includes html elements. For example:

var thisString = "This string has html elements like <b>bold</b> and <u>underline</u>";

I am trying to use this string in an email so that the word bold is actually bold and underline is underlined, rather than displayed as a string.

gs script file:

var template = HtmlService.createTemplateFromFile('Email');                                                                                                                                                                                                         
template.message = thisString;
var message = template.evaluate();
MailApp.sendEmail({
      to: toEmail,
      subject: 'Subject',
      htmlBody: message.getContent()
});

html file:

<html>
<?=message?>
</html>

The email is sent with body exactly as the string.

1 Answer 1

2

You should use force-printing to prevent Apps Script from escaping HTML.

<html>
<?!= message ?>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.