【发布时间】:2021-05-17 11:15:04
【问题描述】:
使用此脚本,我将根据工作表中的某些字段发布两封不同的电子邮件(索引 1 或索引 2),但我需要从 google 驱动器添加一个 .docx 文件作为已发布电子邮件的附件
这是我到目前为止的脚本,它正在运行我只需要将 docx 添加为来自谷歌驱动器的附件文件。请帮助p
//Pulling all data from spreadsheet variables
var SpreadsheetID = "sheet id";
var SheetName = "namesheet";
var now = new Date();
var ss = SpreadsheetApp.openById(SpreadsheetID)
var sheet = ss.getSheetByName(SheetName);
var range = sheet.getDataRange();
var data = range.getValues();
function project_Notification() {
Logger.log(sheet.getLastRow() + " Is the last Row.");
for (var row = 1; row < sheet.getLastRow(); row++) {
var Notification = (data[row][12])
var Email_sent = (data[row][13])
var Admin_email = (data[row][5])
if (Notification == "Yes" && Email_sent == "" && Admin_email != "") {
Logger.log(Notification)
SendEmailConfirmation(data[row][5], data[row][1], data[row][14], data[row][3], data[row][6], data[row][9], data[row][10], data[row][11])
var Notification_cell = sheet.getRange("N" + (row + 1));
Logger.log("N" + (row + 1))
var Today = Utilities.formatDate(new Date(), "GMT", "dd/MM/yyyy");
Notification_cell.setValue(now);
}
}
}
function SendEmailConfirmation(email, Company, Admin_Name, Manager_Email, Landing_Page, QL_code, QL_url, PS_code) {
if (email != "" && Landing_Page != "") {
Logger.log(email)
var admin = {
"name": Admin_Name,
"company": Company,
"landingPage": Landing_Page,
"QLcode": QL_code,
"QLurl": QL_url,
"PScode": PS_code
};
var html1 = HtmlService.createTemplateFromFile('Index1.html');
html1.name = admin.name;
html1.comp = admin.company;
html1.landingPage = admin.landingPage;
html1.qlcode = admin.QLcode;
html1.qlurl = admin.QLurl;
var html2 = HtmlService.createTemplateFromFile('Index2.html');
html2.name = admin.name;
html2.comp = admin.company;
html2.landingPage = admin.landingPage;
html2.qlcode = admin.QLcode;
html2.qlurl = admin.QLurl;
html2.pscode = admin.PScode;
var aliases = GmailApp.getAliases();
Logger.log(aliases);
if (aliases.length > 0 && Landing_Page == "Product1") {
GmailApp.sendEmail(email, "Get started with your trial on Product1", '', {
'from': "product1@gmail.com",
replyTo: "product1@product.com",
cc: Manager_Email,
htmlBody: html1.evaluate().getContent()
});
} else if (Landing_Page == "Product2") {
GmailApp.sendEmail(email, "Get started with your trial on Product2", '', {
'from': "product2@gmail.com",
replyTo: "product2@product.com",
cc: Manager_Email,
htmlBody: html2.evaluate().getContent()
});
}
else {
GmailApp.sendEmail("products-admins@gmail.com", 'Script error', 'Please check the Products overview sheet for errors.');
}
}
}
//Send email for a confirmation that the script run correctly
【问题讨论】:
-
您似乎不小心删除了帖子中的大部分信息,但在剩余的部分中仍然使用“此脚本”来引用它。我为你解开了那个。一般情况下,请不要在得到答案后编辑问题。问题应保持与答案之前一样完整和可回答。包括您最初提供的有用信息。
标签: email google-apps-script attachment email-attachments