Read a Random Post

Delete only Attachments in Gmail without Deleting the Emails using Google Docs

Written by

Topics: Tips & Tricks

delete only attachments from emails in Gmail using Google Docs

Gmail offers us nearly 10 GB of free storage for our inbox. It might look sufficient enough but if you are an active user, over a period of time you very well might end up using all of the available space. Most of the time the culprit would be bulky attachments that sits in your inbox occupying unwanted memory.

What to do in such a situation?

You can buy extra storage from Google or other alternative would be to track down those email message containing large attachments and delete them. Gmail does offer an undocumented operator called “SIZE” which you can use to find bulky emails. EG: SIZE:1MB. After which you can select all those messages and trash them to reclaim space.

But there might be situations where you actually don’t want to delete the original email chain because they may contain valuable information which you prefer to retain but wish to trash the attachments alone or create a backup of them and remove it from the original message to save space. This feature is currently not available in Gmail but some possible solutions are to use desktop email clients, tools to set up account locally via IMAP and then manually do the process of deleting big attachments.

So here is an alternative I came up with that does not require any desktop software and the process is entirely automated. In this article we are going to discuss how to use Google Docs to delete only attachments in Gmail without deleting original messages.

How Does this Work?

1. You specify the size of the emails to be found in Megabyte.

2. All emails with that or above that size are retrieved and shown.

3. On select of delete all, those emails are processed.

4. All attachments in the message are backed up in your Google Drive under the folder name Gmail_Attachments. So they will remain safe there you can refer them whenever needed.

5. Copy of email body is created and it is sent as a new email to your account from your own ID.

So is the time stamp and sender details of original message lost?

No. They are fetched and appended to the new email copy. Details like date, from, to, cc are retained.

remove only attachments in gmail messages

6. Finally original email along with the attachments are trashed.

Delete Attachments Only in Gmail without Deleting Emails with Google Docs

1. First log-in to your Google Docs account.

2. Make copy of the spreadsheet by clicking here. Then click Yes, make a copy.

3. Wait for sometime for the menu Strip Email Attachments to appear just next to help menu.

4. Now mention the size in cell D4 and select Load Emails from the menu. Click OK in authorization popup then click on Grant access followed up by close. Again select load emails and wait for sometime. All email of that size and above it will be fetched and displayed.

Find emails in Gmail of specified size

5. Once it’s done,select delete attachments from the menu. That’s it. Now sit back and wait for sometime while all messages are processed. If everything went well you will see success in status column. You will also be constantly updated with ongoing process status via messages at right bottom of your screen.

Gmail delete attachments alone in emails

6. Finally check your inbox if you have got all the emails with just body sans the attachments and check Google Drive to see if all your files are there. Trash folder will contain all the delete messages.

Video Demo:

Other useful Gmail Tools and Resources:

Forwarding multiple emails at once in Gmail
Get free SMS alerts whenever receiving new emails on Gmail

Did it work out for you? Or any difficulty to follow the steps? Feel free to drop in without your suggestions or queries. In case if you have found any bugs do report it. Cheers!

67 Comments For This Post I'd Love to Hear Yours!

  1. Asiru Nasir says:

    I mainly used gmail for all mailing purpose, I love all the features of gmail, this one is also great, bcoz some time we need to forward some mails without attachment…

  2. Phelix says:

    Many thanks for the post, sounds very interesting but didn’t work for me. I got error “TypeError: Cannot read property “length” from undefined”. I don’t know if it could be a problem of language (Spanish gmail account on a French computer)… Any ideas?

    • Shunmugha Sundaram says:

      Can you please tell me when did you get this?

      On selecting which option? Load Emails or Delete Attachments

      Note: In first place did you mention the size in D4?

      • Phelix says:

        Hello, thanks for your help!

        I did the following:
        1. Log-in on Google Docs
        2. Copy the spreadsheet
        3. Enter “10” in D4
        4. Click on “Load Emails”, got the error message

        I have tried again in a different computer (now Spanish Windows 7, before on French Windows XP) with different browser (now Chrome, before Firefox), and I have the same error.

        • Shunmugha Sundaram says:

          Ideally it should work. I tried to replicate but it worked for me. OK did you authorize and grant access? The first time when you click Load Emails there would be a pop up did you get that? Also do you have a normal Gmail account or Google Apps account?

          • Phelix says:

            Yes, of course. First time I click on Load mails I had a pop up, and I granted the access as required. The mail I am using is a normal Gmail account, but I also have a Google Apps account, I will try later on this one also and let you know.


          • Shunmugha Sundaram says:

            Well. In that case we need to debug. I will send you updated code snippet with some alerts in it to your email along with instructions is that OK for you? Will we continue our discussion there?

        • Shunmugha Sundaram says:

          Please try this. Go to Tools->Script Editor then select all and delete the entire code. Paste the code available at
 and save it. Now as before select Load Emails. You would be getting series of alerts. Just note them down and let me know.

        • john says:

          where do I get “Strip Email Attachments” for my gdocs spreadsheet?

  3. Wisdomtooth says:

    This is excellent, Shunmugha! Much better than doing it via Thunderbird.

    Two suggestions:

    1. The script is creating an email copy for each extracted attachment. We need only one. Put the trash action outside the attachment loop.

    2. It’d be good to keep a link to the attachments in the newly created email. That’s what Google should do but is not doing because that would defeat the purpose of offering their freemium model.


  4. JeffreyG says:

    The tool works but not quite as I had expected. apparently it loaded my ENTIRE mailbox, At least those above 5 MB I think a preset ? (did not do the size bit first). I noted that, so in the spreadsheet I deleted the rows of all other mails I did not want processed and selected delete attachments. And guess what – The script deleted all attachment in all emails in the entire mailbox, hence there is not a (proper) link of the mails you see in the spreadsheet and those mails the script has (secretly) selected – this is a serious shortcoming !. And could I find in time how to stop this script – Nowhere to be found, even killing the tab with the script had no effect. Please please tell us (big fat red button) how to STOP and how to DELETE the script

    Now I am not amused anymore (mildly put) and blame myself for not having a backup copy before I started this.(this is a suggestion – how do we do that ?) Any way to return to the situation before would have been welcome. Another issue is that I do not like that the email with the deleted attachment is sent again and appears as a “new” email – it screws up the date of where it resides in the mailbox (no longer under the original date) and more importantly you cannot directly reply anymore to the original sender as the sender is now in all cases myself… That is another shortcoming – surely there must be smarter ways… . Lastly as another gent noticed – an original mail with severa;l forth and back history is split up in its parts and sent back to me as individual mails – That is quite unwanted too.

    So in all a powerful tool (too powerful…)but it needs some serious refinement. Regards

    • JeffreyG,

      Thanks for your valuable feedback!

      – Script ideally will only search and filter emails based on size you entered not the entire mailbox.
      – Selecting which email to be processed from Spreadsheet is not supported that’s the reason it considered all the emails. The Spreadsheet just gives you a view.
      – Certainly you need not worry about backup because script internally creates one in your Google Drive please check Gmail_Attachments folder. Moreover they are still in your trash to be recovered.
      – When creating a email copy it will be sent as a new email only. The problem of original date getting messed up is addressed by embedding them inline in email. You can still search the email with the original date and you will be able to find the mail.

      Gmail message original date retained

      But surely will try incorporating suggestions you made. But sorry to say that most of them are currently not possible because of the limitations of Gmail API.

      Again Thanks for taking your valuable time to share your views :D

  5. Pedro Failla says:

    After Load Email, if I delete the row with determined email I prevent this email to have the attachments deleted?

  6. cabdouch says:

    Thank you for the app, I got the following error:
    Exceeded maximum execution time

  7. Sun says:

    Thank you for the script.

    When we click Load Emails again, it’d be nice if the previous filled rows from row 8 and on are cleared. It is confusing because I have 10 years of emails I want to process. I get the “Exceeded maximum execution time” but have re-running the script manually with success.

    I am doing in this preparation for an imapsync (IMAP e-mail migration) from one Personal gmail account to another Personal gmail account.

  8. Rob says:

    Thanks for the great addition to a much needed feature of Gmail. I have used Thunderbird’s manual process for years but it requires the following steps:

    1) Select the email message within Thunderbird. Click show headers. Copy subject.
    2) Find the message (usually manually searching via subject) in web browser for
    3) In Thunderbird, go to File, attachments, save all (then choose the path to save)
    4) In Thunderbird, go to File, attachments, delete all. The message is either still selected or gone from Thunderbird view (if sorted by size)
    5) Go to web browser, search again. Normally it may take a minute or two to update (independent of network speed). It should then show an additional message in the thread.
    6) When an additional message number is in the thread (i.e., went from 5 to 6), expand the thread. One message will have the attachment, another will have the attachment shown with 1k size and with filename prefix of “Deleted: “.
    7) Delete the email in the thread with the original file (not the one with “Deleted: ” file prefix.
    8) Go to step 1 and continue until you’ve regained enough space to call it quits.
    9) After you’re done, go to trash, empty trash

    What a pain!

    The method here doesn’t preserve the original thread or the original date of the email. The process with Thunderbird does, however. Is there a way to make your script emulate what Thunderbird is doing here? That would be ideal and far better than the manual Thunderbird process above. I tried IMAPSize but it isn’t supported since 2008 and I don’t think it does the same as Thunderbird (but I could be wrong).


  9. bob mcconnaughey says:

    would it be easy to implement an option to, say, restrict selected emails by attachment type? I’m really only interested in deleting encrypted/zipped data files…*.7z or .ZIP, i’m happy to keep the pictures and mp3s…i’m not worried about space, but about security. I’ll delete the problematic files out of the storage folder as we go!
    *and…is there a flag to keep allow a longer “run time”? I’m timing out after 40-50 messages out of 1000s

  10. Jonathan says:

    Thanks SO much! This is awesome!
    Is there a way to exclude an email or two that I don’t want stripped?

  11. John Michael says:

    Great script. However I keep getting this message: Exceeded maximum execution time.

  12. Anthony says:

    Great idea for a script / app. Was wondering how it’s coming along, have you worked out a lot of the bugs?

  13. Mirri says:

    Thank you for this info – however, did you know google docs storage counts toward your 15 gb and doesn’t help – what DOES help is DELETING YOUR TRASH FOLDER! I found this in gmail documentation, and it says trash counts toward your allocation. After trying to run the script for several times and timing out, I did this research. My gb’s went from just under 15 to 4.5 in a flash! Although the folder says it gets emptied every 30 days, don’t believe it, just go and do it yourself.

    • Mirri,

      Thanks for your valuable inputs. Hopefully it should help others too. Actually believe when I wrote the script the available storage wasn’t shared across Google apps this may be a new change possibly.

  14. Karthik says:

    Fantastic. I had exhausted my storage, and was breaking my head on how to delete attachments without deleting the email. This solved it.


  15. Swift Arrow says:

    Thanks for making this!

    One problem: when I search in Gmail for has attachment over 7MB, I get hundreds of results.

    However, when I run the script in this doc, I get only about 80 results.

    Is this a bug?

  16. Travis says:

    very smart tool. thanks.

    I would like to request that inline images also be downloaded before removal.

  17. Ray says:

    Thank you for this tool but I am having an issue with it. I am a google docs user. I selected for 5MB e-mails to be removed but it did more than that. I have one file that 3.7MB and it is set for deletion. I have a bunch of others also but justed used that one as my example. Any suggestions on how to proceed?

  18. oren says:

    hey, great service you’re doing here. anyhows, just a question- when i just run the script, if the attachment is part of a mail that contains several back&forths, it’ll send me each of those back&forths as a seperate e-mail, which is a mess. i wonder- if, after i load all the emails to the docs, i’ll delete all the rows that contain just the back&forth that include the attachment, it’ll save the rest of the mail?

    • Oren,

      System does not allows to process an email thread together instead you can process then only as individual messages. Hence this behavior. Also you should not be modifying the sheet manually once it’s load.

      Will try adding feature soon that will allow you to delete mails selectively.

  19. oren says:


  20. Singring says:

    I received:

    Status Error EncounteredException: Service invoked too many times for one day: email.

    What is the limit here? Is there a way around it?

    Great script!

  21. Singring says:

    Is it possible to alter the script so that sizes less than 1 MB can be the minimum?


  22. Singring says:

    How would I change the code if I wanted to find all attachments that were 500 KB and above. Would that be possible?

  23. Erin says:

    Effing brilliant, really.

    Any chance you could add the ability to choose a date range, so I could choose to eliminate the attachments only on those emails sent or received up to / between specific dates?

    I will def share this!

    Thanks again!

  24. Daniel says:

    So I was just running this (it’s the second time I’ve tried it – the first was back in November). It seemed to be running fine until I exceeded daily quota, as others have mentioned above. Nothing you can do about that, obviously.

    That being said, a couple issues:

    1) I thought this was supposed to retain the original e-mail date/time? It seems to have created all new e-mails with today’s date/time. Am I incorrect about that?

    2) This script transfers the attachments to Google Drive, as intended. I then went into Google Drive and deleted them (and emptied the trash). However, despite this, it doesn’t look my space usage has gone down. Am I missing something?

  25. Markus says:

    Well done – thank you so much!

    OK – it has some limitations, but it’s the best working solution so far – which is a little bit embarrassing for Google not to provide their own full working solution.

  26. E-SOFT inc. says:

    Wow! Thank you so much!

  27. Prem says:

    this is a good tool.
    Similar to the “size” on D4, can you please add a search string so that I can find some emails to delete ( as an additional filter ).

Leave a Comment Here's Your Chance to Be Heard!