简体   繁体   中英

Google Apps Script Line Separation

When I ask the script to send email as HTML everything is all in one line. If I do text only, each line is separated. Is there a way to separate each line of the responses?

function SendGoogleForm(e) 
{  
  try 
  {      
    var email = "ma*******@email.com"
    var subject = "";  
    var s = SpreadsheetApp.getActiveSheet();
    var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];    
    var message = "";         
    for ( var keys in columns ) {
      var key = columns[keys];
      if ( e.namedValues[key] && (e.namedValues[key] != "") ) {
        message += '<strong>' + key +  '</strong>' + ' --> '+ e.namedValues[key] + "\n\n";
      if (key === "Location") 
        subject += e.namedValues[key] + " "; 
      }
    }

    GmailApp.sendEmail(email, subject, "", { htmlBody: message});

  } catch (e) {
    Logger.log(e.toString());
  }

}

As @Cooper have said you need to change \\n\\n for <br/> .

Line break in HTML are defined with the br tag .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM