DEV Community

Muhammad Ahmad Khan
Muhammad Ahmad Khan

Posted on

How I can send emails with the formatting I've done in google sheet by using app script?

Hi everyone. I'm trying to send emails with google app script by running following code in script editor

// This constant is written in column C for rows for which an email
// has been sent successfully.
var EMAIL_SENT = 'EMAIL_SENT';

/**

  • Sends non-duplicate emails with data from the current spreadsheet. */ function sendEmails2() { var sheet = SpreadsheetApp.getActiveSheet(); var startRow = 2; // First row of data to process var numRows = 2; // Number of rows to process // Fetch the range of cells A2:B3 var dataRange = sheet.getRange(startRow, 1, numRows, 3); // Fetch values for each row in the Range. var data = dataRange.getValues(); for (var i = 0; i < data.length; ++i) { var row = data[i]; var emailAddress = row[0]; // First column var message = row[1]; // Second column var emailSent = row[2]; // Third column if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates var subject = 'Sending emails from a Spreadsheet'; MailApp.sendEmail(emailAddress, subject, message); sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT); // Make sure the cell is updated right away in case the script is interrupted SpreadsheetApp.flush(); } } }

The problem which I'm facing with this code is its not show the bullet points and anchor text I've formatted in my google sheet. I'll appreciate any help regarding to solve this problem.
Have a good day!

Top comments (0)