[英]Gmail App Script Add BCC from Spreadsheet
I have created this code to send a template email from Google Spreadsheet. 我已创建此代码,以从Google Spreadsheet发送模板电子邮件。 I really need to BCC another recipient. 我真的需要密送其他收件人。 I have checked out Class Gmail App. 我已经检出了Gmail类应用。 It didn't quite make sense to me. 这对我来说不太有意义。
var EMAIL_SENT = "EMAIL_SENT";
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menu = [{
name: "Send Email",
functionName: "sendEmails2"
}];
ss.addMenu("Send Email", menu);
}
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 3)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = "Hello Team,\n\n" + row[1] + " Please do the Following:..."; // Second column
var emailSent = row[2]; // Third column
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "Team Email";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
Check the version of sendEmail(recipient, subject, body, options)
method with optional arguments, which can include bcc
. 使用可选参数检查sendEmail(recipient, subject, body, options)
方法的版本,该参数可以包含bcc
。
Class GmailApp also has a similar method sendEmail(recipient, subject, body, options)
, which can include bcc
. GmailApp类也具有类似的方法sendEmail(recipient, subject, body, options)
,其中可以包括bcc
。
Example: 例:
...
var options = {
bcc: 'bccmail0@domain.ext, bccmail1@domain.ext'
};
MailApp.sendEmail(emailAddress, subject, message, options);
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.