Search code examples
google-apps-scriptgmail

Format the body text of a gmail using Google Apps Script


I'm trying to figure out 'how-to' format the body of a Gmail that is created and sent via Google Apps Script. I've added <bold> to the message, but it does not bold the text, it only displays the characters <bold>.

Can someone please point out what I'm missing?

Thanks

var emailAddress = row[34];  // adminEmail column
var message = "<html><body>The " + row[9] + " event that was submitted by <bold>" + row[1] + "</bold> has not been approved yet. Please go to " + row[27] + " and review the admin notes.</body></html>";       
var subject = "An alert for " + row[1] + " needs approval"; 
MailApp.sendEmail(emailAddress, subject, message); 

Solution

  • try this:

    var emailAddress = row[34];  // adminEmail column
    var message = "The " + row[9] + " event that was submitted by <b>" + row[1] + "</b> has not been approved yet. Please go to " + row[27] + " and review the admin notes.";       
    var subject = "An alert for " + row[1] + " needs approval"; 
    MailApp.sendEmail(emailAddress, subject, '', {
      htmlBody: message
    });
    

    use sendEmail(recipient, subject, body, options) you can use the option htmlBody to enter HTML

    see documentation here.

    also <bold>doesn't work and is not a valid HTMLtag so use <b></b> instead