0

Here I'm sending mail using google apps script and it's working fine. but in email body in need some message in bold i.e, ${Number}

  • const Recipient = `test@gmail.com, test2@gmail.in`;
    
  • const Subject = `You got a new mail: ${Number}`;
    
  • const Body    = `Dear User,\n\n New mail received:\n\n\
    number:    ${Number} \n\tName: ${name}\n\tEmail: ${email} \n\nBest   
    regards,\n name`;
    
  • GmailApp.sendEmail(Recipient,Subject,Body);
    
Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51
Sandeep
  • 15
  • 6
  • In your situation, will you use an HTML body? Or, are you required to achieve this using the text body? – Tanaike Apr 11 '23 at 08:35

1 Answers1

1

In order to bold specific texts in the email, you need to use HTML tags by using htmlBody like this:

function myFunction() {

  let Number = 11, name = 'Joe', email = `test@gmail.com`;

  const Recipient = `test@gmail.com`;

  const Subject = `You got a new mail: ${Number}`;

  const Body = "Dear User,<br><br> New mail received:<br><br> number: <b>" + Number + "</b><br>&emsp;Name:" + name + "<br>&emsp;Email:" + email + "<br><br>Best    regards,<br> name "
  var contentHTML = "<body><p>" + Body + "</p></body>";

  GmailApp.sendEmail(Recipient, Subject, Body, {
    htmlBody: contentHTML
  });

}

the code above will bold specific texts by using the <b> </b> tags and please note that you have to convert <\n> and <\t> to <br> and &emsp; so that the HTML can recognize these tags.

Output:

enter image description here

Reference:

bold specific word in email body while sending it through googlescript

How view '\t' (tab) sign in HTML document?

Twilight
  • 1,399
  • 2
  • 11