Si è verificato un errore nel gadget

martedì 10 luglio 2012

Google Drive & attachment Gmail - code, script & app

Here a free script and Its free source code, to save easily our Gmail mail attachments into Google Drive.
I think It's very useful!
I put You also the link to the site that explain How to use It.

http://news.wintricks.it/web/dal-web/36031/salvare-allegati-gmail-google-drive/

This Google Apps Script will automatically save Gmail attachments to Google Drive.
free SOURCE CODE:
http://ctrlq.org/code/19053-send-to-google-drive
If later It was no longer available ;) :

"""
function sendToGDrive() {    

 var sheet   = SpreadsheetApp.getActiveSheet();

// Find the Gmail Label and Google Drive Folder

 var gLabel  = sheet.getRange("D4:D4").getValues();
 var gFolder = sheet.getRange("D5:D5").getValues();

// Search for any news messages with the Google Drive Label
 var threads = GmailApp.search("label:" + gLabel);
 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 {
     // Copy the Gmail attachment to Google Drive
     var file = folder.createFile(att[z]);
     // Wait for a minute to prevent timeout errors
     Utilities.sleep(1000);
    }
    catch (e) {
     GmailApp.sendEmail(
      Session.getActiveUser().getUserLoginId(), 
       "Error: " + messages[z].getSubject(), e.message);
    }
   }       
  }    
 // Message Processed; Remove the Google Drive Label
 GmailApp.getUserLabelByName(gLabel)
         .removeFromThread(threads[x]);
 }
}

// Initialize the Google Apps Script
function configure() {
 var sheet   = SpreadsheetApp.getActiveSheet();
 var gLabel  = sheet.getRange("D4:D4").getValues();
 var gFolder = sheet.getRange("D5:D5").getValues();
  
 if (!GmailApp.getUserLabelByName(gLabel)) {
   GmailApp.createLabel(gLabel);
 }
  
 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);
 }

 // Set a Time-driven trigger for every 5 minutes
 if (ScriptApp.getScriptTriggers().length == 0) {
   ScriptApp.newTrigger("sendToGDrive").timeBased().everyMinutes(5).create();
 }
  
 SpreadsheetApp.getActiveSpreadsheet()
  .toast("That's it. Google Docs will monitor your mailbox in the background.",
         "Close Window", -1);
}

// Create the Gmail menu in Google sheet
function onOpen() {  
 var menu = [    
  {name: "Initialize", functionName: "configure"},
  {name: "Run", functionName: "configure"}
 ];  

 SpreadsheetApp.getActiveSpreadsheet()
               .addMenu("Gmail (Click here)", menu);
}
"""





Nessun commento:

Posta un commento