/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Delete Attachments from Gmail without deleting the original message without the need of Desktop Email Clients: Techawakening.org ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Huge Attachments hoging your Gmail Inbox? Want to retain the email messages but not the attachments in it? Use this script to find and delete only attachments from your emails. Attachments are backed up in your Google Drive account. How it works? - It finds all emails with size above what you have mentioned. - Creates back up of all attachments in Google Drive - Creates a copy of Email body and mails you back the same. - Trashes the original message. Will sender's information, email time stamp be lost? No. They will be retained within the new email copy. Details like from, to, date, cc are appended into the email body. ====================================================================================================================================== For instructions, go to http://techawakening.org/?p=1842 For queries, bugs reporting comment on the above article. Written by Shunmugha Sundaram for Techawakening.org - December 02, 2012 */ var spreadsheet=SpreadsheetApp.getActiveSpreadsheet(); var sheet = SpreadsheetApp.getActiveSheet(); var isloaded=0; function processemails() { var size_att = sheet.getRange("D4:D4").getValues(); var firstmsg=UserProperties.getProperty("firstmsgid"); var isloaded=UserProperties.getProperty("isloaded"); var firstmessageId=getfirstmsgid(); spreadsheet.toast("Please wait while emails are processed to delete attachments. It could take few seconds", "Status", -1); if(size_att!='') { if(firstmsg==firstmessageId) { if(parseInt(isloaded)) { var threads = getthreads(); var folder = getdocfolder(); var row = getFirstRow()+1; var from,date,to,cc,removedatt,archivedata; if(parseInt(threads.length)!=0) { for (var x=0; x"; date="Date: " + messages[y].getDate()+ "
"; to="To: " + messages[y].getTo()+ "
"; cc="cc: " + messages[y].getCc()+ "
"; archivedata="Original Email Information:
*****************************************************************
" + from+date+to+cc +"
*****************************************************************
"; GmailApp.sendEmail(Session.getActiveUser().getUserLoginId(), messages[y].getSubject(),"", {htmlBody:archivedata + messages[y].getBody()}); spreadsheet.toast("Successfully created copy of email body along with sender information", "Status", 5); //Delete Original message once copy is made to free up space messages[y].moveToTrash(); spreadsheet.toast("Trashed the original email along with attachments", "Status", 5); sheet.getRange(row,5).setValue("Success"); row++; } } catch(err) { spreadsheet.toast("Error Encountered" + err, "Status", 8); } if(x==threads.length-1) { spreadsheet.toast("Done. Processed all emails. See your inbox for email backup and Google Drive for attachment backup", "Status", -1); } } } else { spreadsheet.toast("No emails found matching your query. Try searching with smaller size."); } UserProperties.setProperty("isloaded",0); } else { spreadsheet.toast("Please first load emails before trying to delete attachments", "Status", -1); } } else { spreadsheet.toast("New emails have been found or Emails have been deleted. Updating the Sheet again", "Status", 8); getEmails(); } } else { Browser.msgBox("Size field cannot be empty"); spreadsheet.toast("Size field cannot be empty", "Status", -1); } } function getdocfolder() { var folderlist = DocsList.getAllFolders(),available = 0,folder; for (var i=0; i