Script to use GAM for deleting emails using Message ID

3,661 views
Skip to first unread message

Neil

unread,
Sep 9, 2021, 9:02:20 AM9/9/21
to GAM for Google Workspace
Hi folks, 

wondering what a script would look like to turn the command below into something which can bulk delete emails based on message ID. So say I had 10 message ID's, what would a script look like for deleting all those emails? OR perhaps a bulk command using GAM and no script. 

gam all users delete messages query rfc822msgid:xxxxxxxxxxx=g...@mail.gmail.com doit

Any help is appreciated. 

Ross Scroggs

unread,
Sep 9, 2021, 10:37:40 AM9/9/21
to google-ap...@googlegroups.com
Neil,

Make a CSV file (MsgIds.csv) with one column: id
id

gam csv MsgIds.csv gam all users delete messages query "rfc822msgid:~~id~~" doit max_to_delete 1

Ross

--
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/e4725f4d-d943-4ca0-9697-e984209a666fn%40googlegroups.com.


--

Neil

unread,
Sep 10, 2021, 3:24:50 AM9/10/21
to GAM for Google Workspace
Ross, thank you kindly. Worked like a charm. 
Reply all
Reply to author
Forward
0 new messages