2

I am trying to work with existing Google Script, and I'd like to change the color of some words within a sentence in an email the script generates. In the following, I would like "behind pace" to be red. I've tried font tags, but they don't work. Suggestions?

  if (firstItem) {
    body = "This is an email to inform you of course progress.\n\n" + studentName + " is <font color="red"> behind pace </font> in the following subjects:\n";  
    firstItem = false;
  } else { 
    body += "\n";  
  }
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
BPL
  • 21
  • 3

1 Answers1

0

The <span> tag is what you're looking for; there is no <font> tag in HTML (anymore...). The tag accepts a style attribute which uses CSS to describe the look of the span's content. (Learn a bit more about CSS here.)

  if (firstItem) {
    body = "This is an email to inform you of course progress.\n\n"
         + studentName
         + " is <span style='color:red;'>behind pace</span> in the following subjects:\n";  
    firstItem = false;
  } else { 
    body += "\n";  
  }

Notes:

  • You must send this email using the htmlBody option.

    GmailApp.sendEmail(recipient, subject, '', {htmlBody:body});
    
  • Gmail is one of many email clients that only supports in-line styles. See How do I use Google Apps Script to change a CSS page to one with inline styles?

  • Be careful with quotes when embedding strings within strings. In JavaScript, you need to pair up single (') and double quotes ("), but you can nest one within the other, or escape internal quotes ("string \"internal string\" end of string").

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • Thank you for the help, but I still can't make it work. I tried the code Mogsdad suggested, and the email contained this text: "Ima Nutherstoodunt is behind pace in the following subjects:" I am definitely a novice, and I'm editing someone else's script, which I can't entirely interpret. – BPL Oct 23 '15 at 15:41
  • Did you read the "notes" I added? It sounds to me like you're sending the email body as text only, when it needs to be an `htmlBody`. – Mogsdad Oct 23 '15 at 19:46