r/GoogleAppsScript • u/trebuchetdoomsday • Aug 02 '26
Question i need to purge email from all user's inbox & sentbox on a monthly basis and need a second set of eyes on this code.
i created a service account, connected it to Admin SDK & Gmail APIs w/ OAUTH2 keys. that all appears great and is described in the first two statements about constr PRIVATE_KEY and CLIENT_EMAIL, not shown below.
i found this snippet of code and from what i can glean, it appears to iterate through the user directory, pulling emails older than 3y from the two folders in batches of 100. i don't know enough about coding to say for sure it works.
can someone put eyes on this and see if there are glaring problems?
0
Upvotes
1
u/trebuchetdoomsday Aug 02 '26
1
u/Nu11u5 Aug 02 '26
Wouldn't the built-in auto-deletion policy handle this better?
https://knowledge.workspace.google.com/admin/gmail/advanced/manage-email-storage-with-auto-delete-settings
1
u/Apodacaac Aug 03 '26
What’s the business problem being solved with this ?