2

The email recipients are using Gmail.

So I saved this page as an HTML file (named index.html) and I put it in my drive to be able to send it. The problem is that the page is not displayed correctly when I send it.

function sendEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // Start at second row because the first row contains the data labels
var numRows = 2; // Put in here the number of rows you want to process

// Fetch the range of cells A3:E3
// Column A = Name, Column B = Email, Column C = Message, Column D = Message1, Column E = Message2
var dataRange = sheet.getRange(startRow, 1, numRows,4)

// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[2]; // First column of selected data
var message = "Hey, Welcome"; // Assemble the body text
var subject = "Sending emails from a Spreadsheet";
var file = DriveApp.getFilesByName('INDEX.HTML');
if (file.hasNext())
MailApp.sendEmail(emailAddress, subject, message, {
attachments: [file.next().getAs(MimeType.HTML)],
name: 'Welcome to Singa Toulouse'});

}
}

Can someone send help pls

Mikasa
  • 21
  • 3

1 Answers1

1

Tl;Dr:

As your email reciepients are using Gmail, you should know that the Gmail file attachment previewer will not show the attached HTML files as they are shown in a web browser. You should rethink how you will deliver your content to your recipients.

Related

Resources


You are sending an HTML file as an attachement by email. The way that the attachments are displayed to the email recipients depends on the email client that they use, not on Google Apps Script.

Some email clients shows attachments using a general file previewer other might use the default web browser but usually they will show them with some limitations to prevent risks. I.E. JavaScript will be blocked as well images referred by src attribute.

If you are able to ask your email recipients wich email client they use, create an specific HTML file for each email client, otherwise you should choose which email clients are more commonly used by your email recipients and send them an appropiate file.

Another option is to give them instructions to download and open the file by using a supported web browser.

One more option is to design your content to be included in the HTML body of the email message instead of attaching an HTML file.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166