google-apps-scriptgmailhorizontal-line

Add horizontal line to the Gmail body using Google Scripts


I am working with data from a Google Spreadsheets obtained from a Google Forms and I want to send an email of response to a customer. That's why I created a Google Script.

Is it possible to add an horizontal line/rule to the Gmail body using GmailApp.sendEmail(...)? Something like:

GmailApp.sendEmail('example@gmail.com', 'Title', 'Hello.\n\n[CommandForHR]');

I know I can use '---------' to simulate the bar, but I am curious if there exists such command in Google Script.

Searchs

I have searched on the Google Developers webpage but the results are for Google Docs, not Gmail App.

From above, this seems to be the command I am looking for, but I don't know how to implement it inside the parameters of GmailApp.sendEmail(...).


Solution

  • Q1: Is it possible to add an horizontal line/rule to the Gmail body using GmailApp.sendEmail(...)?

    A1: In this case, when the HTML body is used, the horizontal line can be put using <hr>. The sample script is as follows.

    GmailApp.sendEmail("mail address", "sample subject", "sample text body", {htmlBody: "sample text 1<br><hr>sample text 2"});
    

    Q2: Since you have found the htmlBody I don't need anymore the 3rd parameter of sendEmail so: For a correct syntax do we have to write "" as 3rd parameter?

    A2: If you doesn't use the text body, you can also modify above script as follows.

    GmailApp.sendEmail("mail address", "sample subject", "", {htmlBody: "sample text 1<br><hr>sample text 2"});
    

    or, you can also use MailApp.sendEmail() as follows.

    MailApp.sendEmail({to: "mail address", subject: "sample subject", htmlBody: "sample text 1<br><hr>sample text 2"});
    

    References: