使用 MailApp.sendEmail 脚本用 google sheet 字段填充 HTML 正文
Populate HTML body with google sheet fields using MailApp.sendEmail script
我正在尝试使用 HTML 模板发送自定义电子邮件,使用在 google sheet 上收集的数据。我已将代码链接到一个按钮,这样我 select row/rows 我想发送电子邮件,单击该按钮,它就会发送给该行中的收件人。我还希望电子邮件的 body 包含行中的数据。我正在使用 html 正文脚本。我尝试使用相同的 email[column #]
从 html 脚本中的 sheet 调用数据,但无济于事。 如何从我的 sheet 中获取字段来填充 html 脚本以发送自定义电子邮件?
这是我目前使用的代码:
function email() {
var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();
var rng = SpreadsheetApp.getActiveSheet().getActiveRange()
var email = rng.getValues()[0];
MailApp.sendEmail({
to: email[23],
subject: 'Show Seats ' + email[1],
htmlBody: htmlBody,
replyTo:'user@productions101.com',
});
}
我还有一个单独的 html 文件也保存在脚本中。我更喜欢将它保存在一个单独的文件中,因为它更便于编辑。
<html>
<head>
<script>
</script>
</head>
<body>
<p>Hello,</p>
<p> </p>
<p>You are CONFIRMED!</p>
<p>No. of Tickets: email[10]</p>
<p>Date/Time:email[2]</p>
<p>CC Charge: $email[14]</p>
<p>Held Under:email[1]</p>
<p> </p>
<p>Tickets will be held at the Box Office. If you are picking up your tickets in advance, they will be available 48 hours before your selected performance. Please note there is no late seating.</p>
<p> </p>
<p>Thanks!</p>
<div><p><a href="http://www.gap.com/" style="font-family: Tahoma; font-size: 13px;"><img src="https://image.ibb.co/d0aDt6/DEH_Signature_Book.png" /></a></p></div>
</body>
</html>
看看使用 Scriptlets with evaluate()
function email() {
var htmlBody = HtmlService.createTemplateFromFile('mail_template');
var rng = SpreadsheetApp.getActiveSheet().getActiveRange();
var email = rng.getValues()[0];
// set the values for the placeholders
htmlBody.tickets = email[10];
htmlBody.datetime = email[2];
htmlBody.cc = email[14];
htmlBody.held_under = email[1];
// evaluate and get the html
var email_html = htmlBody.evaluate().getContent();
MailApp.sendEmail({
to: email[23],
subject: 'Show Seats ' + email[1],
htmlBody: email_html,
replyTo:'user@productions101.com',
});
}
在 HTML 模板中,添加占位符/printing scriptlets :
<html>
<body>
<p>Hello,</p>
<p> </p>
<p>You are CONFIRMED!</p>
<p>No. of Tickets: <?= tickets ?></p>
<p>Date/Time:<?= datetime ?></p>
<p>CC Charge: <?= cc ?></p>
<p>Held Under:<?= held_under ?></p>
<p> </p>
<p>Tickets will be held at the Box Office. If you are picking up your tickets in advance, they will be available 48 hours before your selected performance. Please note there is no late seating.</p>
<p> </p>
<p>Thanks!</p>
<div><p><a href="http://www.gap.com/" style="font-family: Tahoma; font-size: 13px;"><img src="https://image.ibb.co/d0aDt6/DEH_Signature_Book.png" /></a></p></div>
</body>
</html>
我正在尝试使用 HTML 模板发送自定义电子邮件,使用在 google sheet 上收集的数据。我已将代码链接到一个按钮,这样我 select row/rows 我想发送电子邮件,单击该按钮,它就会发送给该行中的收件人。我还希望电子邮件的 body 包含行中的数据。我正在使用 html 正文脚本。我尝试使用相同的 email[column #]
从 html 脚本中的 sheet 调用数据,但无济于事。 如何从我的 sheet 中获取字段来填充 html 脚本以发送自定义电子邮件?
这是我目前使用的代码:
function email() {
var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();
var rng = SpreadsheetApp.getActiveSheet().getActiveRange()
var email = rng.getValues()[0];
MailApp.sendEmail({
to: email[23],
subject: 'Show Seats ' + email[1],
htmlBody: htmlBody,
replyTo:'user@productions101.com',
});
}
我还有一个单独的 html 文件也保存在脚本中。我更喜欢将它保存在一个单独的文件中,因为它更便于编辑。
<html>
<head>
<script>
</script>
</head>
<body>
<p>Hello,</p>
<p> </p>
<p>You are CONFIRMED!</p>
<p>No. of Tickets: email[10]</p>
<p>Date/Time:email[2]</p>
<p>CC Charge: $email[14]</p>
<p>Held Under:email[1]</p>
<p> </p>
<p>Tickets will be held at the Box Office. If you are picking up your tickets in advance, they will be available 48 hours before your selected performance. Please note there is no late seating.</p>
<p> </p>
<p>Thanks!</p>
<div><p><a href="http://www.gap.com/" style="font-family: Tahoma; font-size: 13px;"><img src="https://image.ibb.co/d0aDt6/DEH_Signature_Book.png" /></a></p></div>
</body>
</html>
看看使用 Scriptlets with evaluate()
function email() {
var htmlBody = HtmlService.createTemplateFromFile('mail_template');
var rng = SpreadsheetApp.getActiveSheet().getActiveRange();
var email = rng.getValues()[0];
// set the values for the placeholders
htmlBody.tickets = email[10];
htmlBody.datetime = email[2];
htmlBody.cc = email[14];
htmlBody.held_under = email[1];
// evaluate and get the html
var email_html = htmlBody.evaluate().getContent();
MailApp.sendEmail({
to: email[23],
subject: 'Show Seats ' + email[1],
htmlBody: email_html,
replyTo:'user@productions101.com',
});
}
在 HTML 模板中,添加占位符/printing scriptlets :
<html>
<body>
<p>Hello,</p>
<p> </p>
<p>You are CONFIRMED!</p>
<p>No. of Tickets: <?= tickets ?></p>
<p>Date/Time:<?= datetime ?></p>
<p>CC Charge: <?= cc ?></p>
<p>Held Under:<?= held_under ?></p>
<p> </p>
<p>Tickets will be held at the Box Office. If you are picking up your tickets in advance, they will be available 48 hours before your selected performance. Please note there is no late seating.</p>
<p> </p>
<p>Thanks!</p>
<div><p><a href="http://www.gap.com/" style="font-family: Tahoma; font-size: 13px;"><img src="https://image.ibb.co/d0aDt6/DEH_Signature_Book.png" /></a></p></div>
</body>
</html>