-2

how can I write multiline string google script

"Dear "+mailData.name+","+"Thank you for writing to us. We have received your message about "+mailData.subject+
      " and will get back to you within 24 hours. Until then, you can give us an email sm@g.com\n\n"+
   "Thankyou \r "
Marios
  • 26,333
  • 8
  • 32
  • 52

2 Answers2

0

You can create an html body instead. You also need to modify your MailApp.sendEmail() function to include htmlBody in the arguments.

Here is the solution:

var email_body = 
      `Dear ${mailData.name},  <br/>
      Thank you for writing to us. We have received your message about ${mailData.subject}. <br/>
     and will get back to you within 24 hours. Until then, you can give us an email sm@g.com. <br/>
     Thank you <br/><br/>`
  
  MailApp.sendEmail( {to:mailData.email, subject:mailData.subject, body:email_body,htmlBody:email_body}); // subject

Note that <br/><br/> will generate two new lines and <br/> will generate one.

Read more information regarding Template literals here.

Marios
  • 26,333
  • 8
  • 32
  • 52
0

If you want to add a line break to a plaintext email use "/n" as suggested by #Sounak-Saha in the comment above.

"Dear "+mailData.name+","+"\nThank you for writing to us. We have received your message about "+mailData.subject+" and will get back to you within 24 hours. Until then, you can give us an email sm@g.com"+ "\n" + "\nThankyou"

See Class paragraph here: https://developers.google.com/apps-script/reference/document/paragraph

rgbv
  • 1
  • 1