beano
beano

Reputation: 952

String to html element in email

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.

Upvotes: 0

Views: 84

Answers (1)

Amit Agarwal
Amit Agarwal

Reputation: 11278

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

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

Upvotes: 2

Related Questions