我有一个小问题。我在Drive-Cloud里找到了一个保存附件的脚本。这个功能是成功的,但是脚本保存的图片不正确,如果我想在我的驱动器中打开Gmail保存的图片,所以我只能用GoogleDocs打开它,我没有得到预览。脚本:
function sendToGDrive() {
var sheet = SpreadsheetApp.getActiveSheet();
var gLabel = sheet.getRange("D4:D4").getValues();
var gFolder = sheet.getRange("D5:D5").getValues();
var threads = GmailApp.search("label:" + gLabel, 0, 5);
var folder = DocsList.getFolder(gFolder);
for (var x=0; x<threads.length; x++) {
var messages = threads[x].getMessages();
for (var y=0; y<messages.length; y++) {
var att = messages[y].getAttachments();
for (var z=0; z<att.length; z++) {
try {
var file = folder.createFile(att[z]);
Utilities.sleep(1000);
}
catch (e) {
GmailApp.sendEmail(
Session.getActiveUser().getUserLoginId(),
"Error: " + e.message
);
}
}
}
GmailApp.getUserLabelByName(gLabel)
.removeFromThread(threads[x]);
}
}
function configure() {
var sheet = SpreadsheetApp.getActiveSheet();
var gLabel = sheet.getRange("D4:D4").getValues();
if (!GmailApp.getUserLabelByName(gLabel)) {
GmailApp.createLabel(gLabel);
}
createFolder();
if (ScriptApp.getScriptTriggers().length == 0) {
ScriptApp.newTrigger("sendToGDrive").timeBased().everyMinutes(5).create();
}
SpreadsheetApp.getActiveSpreadsheet()
.toast("You can now close this Google Docs sheet and it will run in the background.",
"Success", -1);
}
function onOpen() {
var menu = [
{name: "Initialize", functionName: "configure"},
{name: "Run", functionName: "configure"}
];
SpreadsheetApp.getActiveSpreadsheet()
.addMenu("Gmail (Click here)", menu);
}
function createFolder() {
var sheet = SpreadsheetApp.getActiveSheet();
var gFolder = sheet.getRange("D5:D5").getValues();
var folders = DocsList.getAllFolders();
var found = false;
for (var i=0; i<folders.length; i++) {
if (folders[i].getName() == gFolder) {
found = true;
break;
}
}
if (!found) {
DocsList.createFolder(gFolder);
}
}
不幸的是,这是一个已知的问题(1239),您可以标记它,以了解何时/如何修复它,并为它投票。