Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line break in a message

With Google Apps Script, how to make a line break in a variable to send mail?

like image 587
Fabrice Avatar asked May 23 '12 13:05

Fabrice


People also ask

How do you start a new line in a text on Iphone?

In order to add a line break, simply bring up the iOS keyboard, hold down the 'Shift' key and then press the 'Return' key at the same time. Refer to the screenshot below to see which two keys we are talking about here.

What is the symbol for a line break?

LF (character : \n, Unicode : U+000A, ASCII : 10, hex : 0x0a): This is simply the '\n' character which we all know from our early programming days. This character is commonly known as the 'Line Feed' or 'Newline Character'.


5 Answers

If you're not sending an HTML formatted message, use "\n". I personally despise HTML formatted e-mail.

like image 71
mzimmerman Avatar answered Oct 05 '22 23:10

mzimmerman


You should use the <br> tag when sending the HTML portion of the email .

Below is a sample on how I compose the same email body, but formatted differently for HTML & plain text. (Not the best code but hopefully it illustrates the point)

function onFormSubmit(e) {
  var subject = "Subject";

  // Collect user data
  var name = e.values[0];
  var email = e.values[1];   // Where user enters his/her email address

  // Generate content - Replace this with what you're composing
  var content = [];
  content.push("Hi " + name);
  content.push("Thanks for submitting the survey!___LINE_BREAK___");
  content.push("Survey Team");

  // Combine content into a single string
  var preFormatContent = content.join('___LINE_BREAK___');

  // Replace text with \n for plain text
  var plainTextContent = preFormatContent.replace('___LINE_BREAK___', '\n');
  // Replace text with <br /> for HTML
  var htmlContent = preFormatContent.replace('___LINE_BREAK___', '<br />');

  MailApp.sendEmail(email , 
                    subject, 
                    plainTextContent ,                    
                    { 
                      name: "Survey Team", 
                      html: htmlContent 
                    });  
}
like image 43
DashK Avatar answered Oct 05 '22 23:10

DashK


Newline in msgBox:

Browser.msgBox('line 1 \\n line 2');

Please note you need to escape '\n' with additional backslash.

like image 37
radekbaranowski Avatar answered Oct 06 '22 01:10

radekbaranowski


I usually use table in my mail but I think <br /> should work

like image 22
Edo Avatar answered Oct 06 '22 01:10

Edo


You can use \r to change line for the GmailApp \\n to change line for the msgBox.

like image 36
d122082 Avatar answered Oct 05 '22 23:10

d122082