Deleting an attachment from a Gmail thread

5,606 views
Skip to first unread message

Alexander Grutza

unread,
Apr 28, 2022, 11:04:30 AM4/28/22
to GAM for Google Workspace
Is there a way to delete an individual email (with attachment) from a thread of emails?

There was a thread of emails one of our users was communicating in with an outside vendor for project work, and they ended up attaching a PII document and sent it to the people on the list. 

We need to delete this particular email (or attachment) from our email system without deleting the entire thread of emails.

Ross Scroggs

unread,
Apr 28, 2022, 11:37:22 AM4/28/22
to google-ap...@googlegroups.com
Alexander,

Every message has a unique Id. Select a message, click on the three dots at the right of the top row and choose Show original, copy it.

gam all users delete message query "rfc822msgid:<Copied Message ID>" doit

Only that message is deleted, no other messages in the thread are affected.

--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/12b6161a-737b-4acc-a979-eeb01256e4ccn%40googlegroups.com.

Alexander Grutza

unread,
Apr 28, 2022, 11:44:56 AM4/28/22
to GAM for Google Workspace
Thanks Ross. Yeah I was in the middle of testing between two test accounts and the below is what I used

gam user username show messages query "subject: ..." showattachments attachmentnamepatern "filename*" headers subject,message-id > emails.csv
Search throught the CSV exported above to make sure I got the correct message-id
create a csv of our users that were sent that message/attachment (only 9 thankfully)
gam csv users.csv gam user ~email delete messages query "rfc822msgid:<.......>" doit

Markus Frömmel

unread,
Jan 2, 2023, 9:56:03 AM1/2/23
to GAM for Google Workspace
is there a way to delete just the attachment, but leave the actual message text in place?

Ross Scroggs

unread,
Jan 2, 2023, 11:24:34 AM1/2/23
to google-ap...@googlegroups.com
Markus,

No, the API only supports deleting the message.

Ross
----
Ross Scroggs



Markus Frömmel

unread,
Jan 2, 2023, 11:45:56 AM1/2/23
to GAM for Google Workspace
I was afraid you'd say that :-D

So if one would really need that I assume one has to download the message, strip the attachment and reinject?

Ross Scroggs

unread,
Jan 2, 2023, 12:11:10 PM1/2/23
to google-ap...@googlegroups.com
Markus,

Theoretically you could do that, I'm not quite sure how to actually accomplish it.

I'll do some looking,

Ross
----
Ross Scroggs


Ross Scroggs

unread,
Jan 2, 2023, 12:38:22 PM1/2/23
to google-ap...@googlegroups.com
Markus,

Send me a Meet/Zoom invitation.

Ross
----
Ross Scroggs


Jay Lee

unread,
Jan 2, 2023, 2:41:15 PM1/2/23
to google-ap...@googlegroups.com
Ross,

You'd need to download the raw email, read it with something like Python's email parsing library, delete the attachment, purge the old email and then import the new attachment-less copy.

LOTS of gotchas and potential edge case messes to deal with there. To name a few:

  1. emails that aren't parsable or contain unusual attachment formatting will need special handling (and in my experience those are sadly frequent)
  2. emails that have the file (usually an image file) embedded in the main body of the email may need special handling since removing them would break the message body. Messages are SUPPOSED to note if an attachment is a real attachment or inline with the body but no tall do correctly (cough Microsoft cough)
  3. you may need to delete the original before importing the modified copy to prevent Gmail from "de-duping" the message. However if you do that and the import fails you're now left without any copy of the message.
The better way to do this IMHO is to:

a) give up on the message entirely (it seems somewhat unlikely the original body is all that valuable without the attachment).  OR
b) pay for more Gmail storage.

Jay

Markus Frömmel

unread,
Jan 2, 2023, 2:48:51 PM1/2/23
to google-ap...@googlegroups.com
Hi Jay,
it's not about the storage for me (although that is a valid use case I haven't actually considered)

My reason was compliance. An attachment was received which should have not been there. Leaving the original email text in place would maybe be better for documentation.

That being said, it's not such a big deal for me. I have given up on saving the email body and just deleted the messages all together. So my particular case has been solved already

Still if you feel that would be a valuable feature Ross, I am happy to contribute with ideas and testing.

Kind regards, Markus


––
Markus Frömmel

You received this message because you are subscribed to a topic in the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/zFONcrJjKaU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CA%2BVVBp_c6bge-LsuVyKiPBoHvUjPEmXjXvsTuH%3DqozJrFpXe7g%40mail.gmail.com.

Jay Lee

unread,
Jan 2, 2023, 2:57:28 PM1/2/23
to google-ap...@googlegroups.com
If it's a question of compliance modifying and re-imporitng the original won't help either since the original and the attachment will remain in Vault. Gmail can't do anything to impact Vault's retention of the message.

(I'm assuming you are using Vault retention since you are concerned about compliance)

Jay Lee


Reply all
Reply to author
Forward
0 new messages