google-apps-script - 超链接 Google Script 中的文本以发送电子邮件
问题描述
我无法在通过 Gmail 发送的脚本上获取文本超链接。
我已经测试了这个站点上的其他文章,但我似乎没有得到正确的代码,因为它会<a href code>
在实际的电子邮件中提取。
下面是我的脚本(不要介意这里的内容更改)。
对于此示例,我想将 var 消息中的 THIS PAGE 超链接到 www.google.com。
知道如何在来自 Gmail 的电子邮件中使用它吗?
function sendemail() {
var spreadSheet = SpreadsheetApp.getActiveSheet();
var dataRange = spreadSheet.getDataRange();
// Fetch values for each row in the Range.
var data = dataRange.getValues();
var text = text;
for (var i = 1; i < data.length; i++) {
(function(val) {
var row = data[i];
var emailAddress = row[1]; //position of email header — 1
var firstname = row[0]; // position of name header — 1
var price = row[2];
var content = row[25];
var contenttwo = row[24];
var html_link = "www.google.com";
var h = row[22];
var upcomingDate = Utilities.formatDate(row[3], "GMT+1", "MM/dd/yy");
//var date = row[3];
var options = {};
var subject = "Here's your info";
var message = "Dear " + firstname + ", " + "\n" + "\n" + content + " $" + price + " xxxxxxxxx" + upcomingDate + "." + "\n" + "\n" + "Please visit this page for more information.";
//MailApp.sendEmail(content)
MailApp.sendEmail(emailAddress, subject, message);
})(i);
}
}
解决方案
可能是这样的:
function sendemail() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var rg=sh.getDataRange();
var vA=rg.getValues();
var text='text';
for (var i=1;i<vA.length;i++) {
var emailAddress=vA[i][1];//col 2
var firstname=vA[i][0]; //col 1
var price=vA[i][2];//col 3
var content=vA[i][25];//col 24
var html_link="http://www.google.com";
var upcomingDate=Utilities.formatDate(new Date(vA[i][3]), "GMT+1", "MM/dd/yy");//if vA[i][3] is a string instead of a date then this may still work
}
var subject = "Here's your info";
var message=Utilities.formatString('Dear %s, <br /><br />%s $%s xxxxxxxxx%s.<br /><br />Please visit <a href="%s">this page</a> for more information.',firstname,content,price,upcomingDate,html_link);
var message1=Utilities.formatString('Dear %s, \n\n%s $%s xxxxxxxxx%s.\n\nPlease visit %s for more information.',firstname,content,price,upcomingDate,html_link);
MailApp.sendEmail(emailAddress, subject, message1,{htmlBody:message});
}
}
推荐阅读
- arrays - 在C中将*char数组的元素设置为NULL
- amazon-web-services - 您能否将 AWS 捆绑包从一个区域复制到另一个区域
- python - 范围内的非均匀分布
- ios - 领域迁移错误:'RLMException':'属性'RecipeStep.recipeId'不存在'
- python - 使用 Python 在当前日期中添加时间
- operating-system - 在操作系统调度程序中使用算法的硬件实现
- python - AWS Lambda 限制 Python 输出
- scala - 如何在 Windows 中为 Intellij Idea 更改 Scala 插件的 C:\Users\Username32\.sbt\1.0\plugins 位置
- .net - PowerShell 类中的 .NET 类型
- angular - Angular:如何在模板内迭代不可变 js Map?