Debye Leon
Debye Leon

Reputation: 21

Change Text to Bold or Add Images using Google Script

This is the Code I have so far and it works great! I just want to know how to change the text to bold and add images if possible.For where it says grows, glows, apropos. I would like that to be bolded for example.

       function sendEmails() {
  var allData,counter,emailAddress,fourRowsOfData,i,lastRow,
      message,messageStart,messageEnd,numRows,
      row,sheet,startRow,studentName,subject;

  //USER INPUT
  startRow = 2;  // First row of data to process
  numRows = 4;   // Number of rows to process
  subject = "Camp Pursuit: Report Card ";
  messageStart = "Dear Parents,"+'\n' +'\n' +
  "Every week at Camp Pursuit, we ask the teachers to make observations about how the kiddos did." +'\n' +
  "We know that one week isn't enough to truly know a child, so we call this our " +"Glows, Grows, & Apropos." +'\n' +
    "Meaning..." + '\n' +'\n' +
    "Glows: Positive things the teacher noticed" +'\n' +
    "Grows: Areas for continued growth" +'\n' +
    "Apropos: Ways to continue your son/daughter's enrichment" +'\n' +
    "We hope you appreciate seeing what the teachers saw last week, and perhaps you can use some of"+'\n' +
    "the recommendations for further enrichment this summer.  Feel free to let us know your thoughts on the camp through our anonymous online survey."+'\n' +
     "Your feedback helps us improve the experience for all kiddos! "+'\n' + 
"Survey Link: https://docs.google.com/forms/d/1g4LvA9a8sdKECr1yvp5uOoPnvKACFm3HvbTBfvQGRyo/viewform?usp=send_form" +'\n' +
"We look forward to seeing your child at our programs throughout the year!" +'\n' +
"Sincerely, "+'\n' +
"The Camp Pursuit Team"
+'\n';
  //END USER INPUT

  sheet = SpreadsheetApp.getActiveSheet();
  lastRow = sheet.getLastRow();

  allData = sheet.getRange(startRow, 1, lastRow-startRow, 10);// Get All data first

  counter = 0;

  while (counter < lastRow-startRow) {
    Logger.log('counter: ' + counter)

    fourRowsOfData = sheet.getRange(startRow + counter, 1, numRows, 6).getValues();
    emailAddress = fourRowsOfData[0][0];  // First column of first row
    Logger.log('emailAddress: ' + emailAddress)

    studentName = fourRowsOfData[0][1];

    messageEnd = "";//Reset on every outer loop

    for (i = 0; i < numRows; i++) {//loop numRows times - once for each row
        row = fourRowsOfData[i];

        messageEnd = messageEnd + '\n' +
            "Class: " + row[2] + '\n' +'\n' +
              "Glows: " + row[3]+ '\n' +
              "Grows: " + row[4] +'\n' +
                "Apropos: " + row[5] +'\n';  
    }

    message = messageStart + "\n" + studentName + "\n" + messageEnd;

    MailApp.sendEmail(emailAddress, subject, message);//Send the email outside of inner loop    
    counter+=numRows;//Increment counter by number of rows to process
  }
}

Upvotes: 1

Views: 2583

Answers (2)

Parag Jadhav
Parag Jadhav

Reputation: 1899

As per the official MailApp Documentation, to send HTML body you'll need to use htmlBody parameter in your MailApp.sendEmail() method. Have a look at the example below (copied from official documentation page)

To make a text bold use <b></b>tag

For example: "This text will be displayed in bold.

To show an image in email use <img src="hostname.com/image.png">

MailApp.sendEmail({
     to: "[email protected]",
     subject: "Logos",
     htmlBody: "inline Google Logo<img src='URL_PATH'> images! <br>" +
               "inline YouTube Logo <img src='URL_PATH'><br>" +
               "<b>Using bold tag</b> ",
     inlineImages:
       {
         googleLogo: googleLogoBlob,
         youtubeLogo: youtubeLogoBlob
       }
   });

Hope this helps.

Upvotes: 4

Anton Dementiev
Anton Dementiev

Reputation: 5716

Use standard html tags in your message string, then pass an empty string "" or 'null' as body parameter in sendEmail() method. Finally, assign your message string to 'htmlBody' property of 'options' parameter. Use 'br' tags for line breaks. Example

function sendEmail() {

var body = "<b>Hello </b> world. <i><Hello /i> world. <br /> New line";

MailApp.sendEmail("[email protected]", "test", "", {htmlBody: body});

}

See 'Advanced parameters' section here https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String,Object)

Upvotes: 2

Related Questions