Csabavagyok
Csabavagyok

Reputation: 69

MailApp sendEmail htmlBody clickable dynamic link

I wrote a script that creates a new Spreadsheet from one of the Sheets of the original Spreadsheet and emails the new Spreadsheet with the PDF version attached and has an html body with some text and the link to the new Spreadsheet. The script fires each morning because the Sheet has dynamically chaning data, so the link also changes with every trigger. The problem is that the link in the html body appears as a text and I would like it to be clickable. I tried formatting it with with A HREF but that wouldn't seem to do the trick

var napijelentes = SpreadsheetApp.create(fajlnev);
var napijelentesfajlid = napijelentes.getId();
var napijelentesfajl = DriveApp.getFileById(napijelentesfajlid);
var napijelentesurl = napijelentes.getUrl();

MailApp.sendEmail({
to: ellenorzes,
subject: subject,
htmlBody: "To download the spreadsheet please follow the link below: <br><a href = \"napijelentesurl\">" + napijelentesurl + "</a><br><br>",
attachments: [napijelentesfajl]
});

This way the link appears in the email as plain text, with [napijelentesurl] in front of it and is still not clickable. Any solutions to my problem?

Upvotes: 1

Views: 2662

Answers (1)

Alan Wells
Alan Wells

Reputation: 31300

Create a variable for the html string.

var h;
h = 'To download <br><a href = "' + napijelentesurl + '">' + 
     napijelentesurl + "</a><br><br>"; 

Use single quotes on the ends of string that need double quotes inside the string.

Upvotes: 1

Related Questions