- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 MailApp 发送 HTML 电子邮件。这是我将从中提取数据的表:
在阅读了 SO 上的文档和帖子后,我仍然无法确定为什么发出的电子邮件在变量部分显示未定义。
如果有人能指出我正确的方向,我将不胜感激。
这些是我的代码:
sendHtmlEmail.gs
function sendEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastRow = ss.getLastRow();
var quotaLeft = MailApp.getRemainingDailyQuota();
if((lastRow-1) > quotaLeft){
Browser.msgBox("You have " + quotaLeft + " email quota left and you're trying to send " + (lastRow-1) + " emails. Emails were not sent.")
} else {
for (var row = 2; row <= lastRow; row++){
var currentEmail = ss.getRange(row, 4).getValue();
var currentContact = ss.getRange(row, 3).getValue();
var currentNewSize = ss.getRange(row,8).getValue();
var currentSub = ss.getRange(row, 9).getValue();
var returnData = [currentContact, currentNewSize, currentSub];
var html = HtmlService.createTemplateFromFile('htmlTemplate');
html.data = returnData;
var template = html.evaluate().getContent();
var subjectLine = "Important notice";
MailApp.sendEmail({to: currentEmail, subject: subjectLine, htmlBody: template});
} //close for loop
Browser.msgBox("You have successfully sent " + (lastRow-1) + " emails.")
} //close else statement
}
htmlTemplate.html
<!DOCTYPE html><html><head><base target="_top"></head><body style="text-align: center;font-family: Arial;">
<div id="center" style="width:300px;border: 2px dotted grey;background:#ececec;margin:25px;margin-left:auto;
margin-right:auto;padding:15px;"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Simple_Alert.svg/600px-Simple_Alert.svg.png"
width="180" style="margin:10px 0px"><br /><div style=" border: 2px dotted grey;background:white;margin-right:auto; margin-left:auto;
padding:10px;"><h2>Alert</h2><h3>Important Notice <br /><br />
+ <?= data.currentContact ?> + '<br />' + <?= data.currentNewSize ?> + '<br />' + <?= data.currentSub ?> + '<br /></h3></div></body></html>'
我知道这与 htmlTemplate data.currentNewSize 等有关,但在调整我的代码后,它们仍然显示未定义,如图所示。
最佳答案
您在方法中使用数组,而模板需要一个对象。
替换
var returnData = [currentContact, currentNewSize, currentSub];
与
var returnData = {currentContact: currentContact, currentNewSize: currentNewSize, currentSub: currentSub}
关于javascript - MailApp 的 html 模板中 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53261064/
这个问题在这里已经有了答案: MailApp.sendEmail method doesn't get through to accounts with URL in the body - Mess
我有一个简单的 MailApp 以 HTML 格式发送文本。我的小问题是:如何在该文本中插入内联图像?例如,我想为荷兰文文本添加荷兰国旗,为法语内容添加法国国旗。 我假设只使用 HTML 代码就可以完
我有一个使用以下脚本的脚本: MailApp.sendEmail(row.shiftManager, "Holiday Approval Request", "", {htmlBody: messag
我对 MailApp.sendEmail() 有疑问. 我尝试通过 Google 电子表格中的脚本发送电子邮件。我的脚本适用于我的帐户,但不适用于我 friend 的帐户。我收到这条消息: Messa
我正在开发一个项目,在 Google Sheet 脚本编辑器中使用 JavaScript 将链接(单击时将激活我的脚本中的功能)嵌入到电子邮件中。我不确定我的代码是否错误或者谷歌是否不允许链接。这是我
我们已经解决了应用程序脚本最后一个函数中的所有错误,一直到此服务器错误。该脚本用于向客人预订发送电子邮件提醒。 该代码特别破坏了 mailapp 函数(第 27 行)。任何意见将不胜感激! funct
我想使用 Google Apps 脚本发送一封包含replyTo 和附件的电子邮件,但我只找到了这两种方法,它们分别执行我想要的操作。 sendEmail(recipient, subject, bo
我有一个用于工作的脚本,昨天(太平洋标准时间 2012 年 10 月 25 日下午 3:53 到下午 4:34 之间)'name' argument of MailApp.sendEmail's ad
我在设置脚本来迭代 Google 电子表格并将包含有关他们的报告的行通过电子邮件发送给员工时遇到了问题。 在我的测试中,电子邮件地址和主题行正在通过电子邮件发送,但根据我尝试的内容,电子邮件要么是空白
emailAddress1=row[0]; emailAddress2=row[1]; MailApp.sendEmail(emailAddress1 + "," + emailAddress2 ,s
我需要询问如何正确使用mailapp.sendemail中的SetTimeOut()函数。 var sendmail2 = date+1*3600000*24; MailApp.sendEmail (
我有这段代码可以使用 Google Apps 脚本发送电子邮件: var message = "Lorem ipsum dolor sit amet, consectetur adipisicing
我在 Google Docs 电子表格中有几个脚本,它们使用 MailApp.sendEmail 发送包含电子表格数据的电子邮件。多年来,他们都出色地工作。大约 2 周前,他们停止发送电子邮件。脚本仍
我正在尝试制作一个应用程序,它会在每次对工作表进行更改时自动向我发送电子邮件。我知道有些通知可以做到这一点,但只有三件事。 我需要在特定的时间和 我需要它到一个特定的电子邮件。 我希望它针对特定范围的
我制作了一个绑定(bind)脚本来扫描其电子表格的记录,如果某些条件成立,则会将电子邮件发送给相应的员工 更具体地说,该脚本是通过一列检查员工列表是否有生日,而不是 true 或 false 值。我的
我正在尝试通过 Google Apps 脚本和 Google 表单自动发送电子邮件。基本上,在提交表单时,它会向所需的电子邮件地址发送一封电子邮件,其中包含 Google 表单上指示的字段。之后,我有
我正在处理 Google Apps 脚本。我正在尝试按如下方式发送电子邮件: function test_sendmail(){ var subject = "subject"; var bo
最近我为客户做了一个脚本。 客户允许我获取必要的文件。 该脚本最终将电子邮件发送到特定地址。 当我在我的谷歌帐户下测试它时,它会在“发送自”字段中发送带有我的 Gmail 地址的电子邮件。 当我的客户
我正在制作一个 Google Apps 脚本,该脚本根据 Google 文档文件中制作的模板发送电子邮件。 Google 文档文件如下所示: Lorem ipsum dolor sit amet, c
我正在尝试使用 MailApp 发送 HTML 电子邮件。这是我将从中提取数据的表: 在阅读了 SO 上的文档和帖子后,我仍然无法确定为什么发出的电子邮件在变量部分显示未定义。 如果有人能指出我正确的
我是一名优秀的程序员,十分优秀!