Line break in a message

后端 未结 4 1031
-上瘾入骨i
-上瘾入骨i 2020-12-03 22:11

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

相关标签:
4条回答
  • 2020-12-03 22:40

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

    0 讨论(0)
  • 2020-12-03 23:01

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

    0 讨论(0)
  • 2020-12-03 23:04

    Newline in msgBox:

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

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

    0 讨论(0)
  • 2020-12-03 23:07

    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 
                        });  
    }
    
    0 讨论(0)
提交回复
热议问题