I am creating an invoicing script add-on for Google Sheets. I want to be able to write in a value for a cell in the sheet that has an email message in it. I now understand how to send an email through Google script, however, I can only send simple messages without any formatting. My end goal is to be able to send an email with an image, chart [that holds the invoice data in it] as well as additional formatting, such as paragraphing and font.
I tried to add HTML into the actual cell, but it just sends the email with the HTML as the message [without any actual formatting applied to the email]. For example: I tried to add two paragraphs by placing the following into the sheet cell B2:
Hello World. \n My name is Jennifer. \n What is your name?
and it came out exactly like that with the \n
written into the message.
function sendEmail2(){
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet3').getRange('B2');
var emailAddress = emailRange.getValues();
//email info
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet3');
var range = sheet.getRange('C2');
var newMessage = range.getValue();
// Send Alert Email.
var message = 'This is your Alert email!'; // Second column
var subject = 'Your Google Spreadsheet Alert';
MailApp.sendEmail(emailAddress, subject, newMessage);
}
The email is sent but without the actual HTML formatting inside the email.
How do we sent emails with formatting through Google Apps Script?