how to rename the link from the getUrl() function

2019-07-31 08:12发布

I have a script that I want to change the name of the url link. The script sends an email with a link to the document. However, I want the link to be "click here" instead of showing the link address. How do I go about doing this? Here is my code.

function sendDoc() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var url = ss.getUrl(); 
var body = "Hi Bo,\n\nHere are the weekly stats " + url;
var thanks = "\n\nThank You,\n   Chris";
var message = body + thanks; 

MailApp.sendEmail(email, subject, message);
 }

1条回答
一夜七次
2楼-- · 2019-07-31 08:17

You need to use the advanced arguments of the sendEmail function:

This should work:

function sendDoc() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var url = ss.getUrl(); 
var body = "Hi Bo,\n\nHere are the weekly stats " + url;
var thanks = "\n\nThank You,\n   Chris";
var message = body + thanks; 

MailApp.sendEmail(email, subject, message, {htmlBody: message.replace('link', '<a href="link">click here</a>')});
 }

Where link is the actual URL that you want to be emailed.

Here is a link to the documentation of the sendEMail function:

https://developers.google.com/apps-script/class_mailapp#sendEmail

查看更多
登录 后发表回答