问题描述
我该怎么做?
示例:
邮寄 = A 列
MailApp.sendEmail({
to: mailling,subject: "test",body: "Test message",
解决方法
如果您的电子邮件位于从第 2 行开始的 A 列中:
function getEmails() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet1');
const emails = sh.getRange(2,1,sh.getLastRow() - 1,1).getValues().flat();
return emails.join(',');
}
function sendEmails() {
MailApp.sendEmail({to: getEmails(),subject: "test",body: "Test message"});
}
,
我认为您应该像评论中建议的那样检查课程的文档,它具有非常好的功能,可以改善您发送电子邮件的方式。无论如何,这里有一个可以帮助您的示例。
function sendMail() {
//Each numer means the column of the sheets thats going to grab the value
var first = 0;
var second = 1;
var third = 2;
//In the Column D must have the emails
var fourth =3;
//Specifies the HTML document that going to give the structure of the email
var emailTemp = HtmlService.createTemplateFromFile("email");
//Tells wich is the sheet to take information
//in this case the sheets name is "Data Base"
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Base");
//Gives the range of the columns that the information is going to be
var data = ws.getRange("A1:E" + ws.getLastRow()).getValues();
//This is an optional filter in the Column F so you can filter wich rows to run
data = data.filter(function(r){ return r[5] == true });
//To use the variables in between the HTML file your going to use the value after "emailTemp." as <?= fr ?>
data.forEach(function(row){
emailTemp.fr = row[first];
emailTemp.se = row[second];
emailTemp.th = row[third];
var htmlMessage = emailTemp.evaluate().getContent();
GmailApp.sendEmail(row[fourth],"HEEERE GOES THE SUBJECT OF THE EMAIL","Your email doesn't support HTML.",{name: "Email",htmlBody: htmlMessage})
});
这里我使用了一个 html 模板来发送包含从其他列中提取的变量的电子邮件。你可以看看这个github