I am trying to create a script that can save all attachments sent by an email id from time to time to a particular drive folder.
I am new to GAS and found this script however it doesn't seem to fit my requirement. Can anyone help, Please??
function GmailToDrive() {
var query = '';
query = 'in:inbox from:noreply@agyo.io has:nouserlabels ';
var threads = GmailApp.search(query);
var label = getGmailLabel_(labelName);
var parentFolder;
if (threads.length > 0) {
parentFolder = getFolder_(folderName);
}
var root = DriveApp.getRootFolder();
for (var i in threads) {
var mesgs = threads[i].getMessages();
for (var j in mesgs) {
//get attachments
var attachments = mesgs[j].getAttachments();
var message_body = mesgs[j].getBody();
for (var k in attachments) {
var attachment = attachments[k];
var isDefinedType = checkIfDefinedType_(attachment);
if (!isDefinedType) continue;
var attachmentBlob = attachment.copyBlob();
var file = DriveApp.createFile(attachmentBlob);
file.setName(renameFile_(attachment, message_body))
parentFolder.addFile(file);
root.removeFile(file);
}
}
threads[i].addLabel(label);
}
}
I am unable to understand the usage of getFolder_(folderName) and checkIfDefinedType_(attachment);
All I need is this: Create a new folder when a new email sends me attachments and save them to that folder...