Line break in message

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

+7
source share
4 answers

If you do not send the message in HTML format, use "\ n". I personally despise HTML-formatted email.

+6
source

You must use the <br> tag when sending part of the HTML email message.

Below is an example of how I compose the same email object, but formatted differently for HTML and 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 }); } 
+4
source

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

+2
source

New line in msgBox :

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

Note that you need to escape "\ n" with an extra backslash.

+2
source

All Articles