Search code examples
emailgoogle-apps-scriptgmailwhitespace

How to send an e-mail to display "\n " newline followed by half width space?


[Problems facing]
If I put a "blank" immediately after entering "\n (line feed)" in the body, the "blank" becomes two.
[Script]

function sendEmail() {
  MailApp.sendEmail({
    to: "test@example.com",
    subject: "Test",
    body: "───────────────\n Hello, world!", //<-1 blank
  });
}

[Result]
───────────────
  Hello, world! <-2 blanks at the beginning


[What I tried]

function sendEmail() {
  MailApp.sendEmail({
    to: "test@example.com",
    subject: "Test",
    body: "───────────────\n&nbsp;Hello, world!",
  });
}

[Result]
───────────────
&nbsp;Hello, world! <-displayed as is

[want to achieve]
I'm asking for one blank display.


Solution

  • You may try Unicode escape sequence with the required whitespace character in unicode(For eg, 200A(hair space) or 2009(thin space)):

    body: "───────────────\n\u{00A0}Hello, world!"