Delete all emails in gmail

136 views
Skip to first unread message

Jason Bochat

unread,
Oct 18, 2022, 3:02:06 PM10/18/22
to GAM for Google Workspace
I'm trying to delete all emails in a user's gmail by using gam user users...@example.org delete messages query all doit

I know it's the query argument I have wrong, I've tried the following after query too with no success:
rfc822msgid:
older_than:3m
left it blank
didn't even type the query argument in

It did run once using gam user user...@example.org delete messages query all doit but it only deleted one message.

Also the maxtomodify or maxto arguments can't be found by GAM           

Jay Lee

unread,
Oct 18, 2022, 4:04:37 PM10/18/22
to google-ap...@googlegroups.com
With:

"query all"

you are searching Gmail for the text "all". The first time you ran you probably deleted emails with the word all in them. To actually delete everything don't specify query at all:

gam user users...@example.org delete messages doit

of course you'll also need to specify maxtodelete to confirm you definitely want to delete more than 1 message (sorry for the hassle on the commands but it's the best way to try to avoid accidental command line disaster)

gam user users...@example.org delete messages doit maxtodelete 99999999999

Jay Lee


--
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/7eb774bc-967c-4a29-9859-405663cef3b0n%40googlegroups.com.

Ross Scroggs

unread,
Oct 18, 2022, 4:10:12 PM10/18/22
to google-ap...@googlegroups.com
Jay,

$ gam user testuser2 delete messages doit


ERROR: No query specified. You must specify some query!


Ross




--

Jay Lee

unread,
Oct 18, 2022, 4:19:01 PM10/18/22
to google-ap...@googlegroups.com
Bah, the API doesn't require a query but I suppose we decide to make it required in order to avoid accidental mailbox-wide wipes.

Jason, you can use:

gam user users...@example.org delete messages query "in:anywhere" doit

Jay Lee


Jason Bochat

unread,
Oct 18, 2022, 4:36:27 PM10/18/22
to GAM for Google Workspace
Thanks! Before I got this I tried older_than:1hr and that worked. I'll follow up after I try in:anywhere

Jason

James SEYMOUR

unread,
Oct 18, 2022, 9:58:14 PM10/18/22
to GAM for Google Workspace
You could also use query before:<yyyy-mm-dd> and specify tomorrow's date
Reply all
Reply to author
Forward
0 new messages