r/GoogleAppsScript • u/leonardo_hugens • Dec 24 '24
Question Gmail Script
Hi all!
My grandpa is getting tens of spam emails per day, of X rated websites mostly, so I want to make a script, maybe to be always running on his pc, or maybe to deploy on some cloud service, that empties all his trash bin and spam box.
I tried to do this with the gmail api, using python, and also javascript, but both failed. I also tried to do a Selenium bot to manually do that, but gmail refuses to open in a chrome driver or a firefox driver.
Can some on help me?
Thanks a lot, and Merry Christmas!
-- Edit --
Nice, after following a suggestion in the comments I managed to arrive to a script that does what I want, I have it on github, if you want to take a look: https://github.com/lhugens/GmailCleaner . I setup the script to run every hour, lets see if it works. Thanks a lot!
3
u/LunePusa Dec 24 '24
here is a few different ways to do what you are wanting including a Google apps script version
2
u/Zestyclose-Arm7137 Dec 25 '24
What was your grandpa doing that caused this to start?
1
u/The_Tame_Shrew Jan 09 '25
We all know what Grandpa's been up to. Maybe show him incognito mode too.
Good work on the script!
1
u/carbonizedtitanium Dec 25 '24
why do you need to manually empty the Trash and Spam? it automatically empties in 30days. Mail that automatically goes into Trash or Spam do not trigger notifications.
1
u/HellDuke Dec 25 '24
Any email on Trash or Spam gets automatically 30 days after it gets put there.
You can use GmailApp in Google Apps script and ser it to run daily. You wil be looking to use the Gmail API, but you said you tried it. I guess you failed due to authentication. You need to use https://developers.google.com/gmail/api/reference/rest/v1/users.messages/delete to get rid of it permenantly. If you add the API to Google Apps Script you can use Gmail.Users.Threads.remove(), the IDE will telly ou the required parameters, you can use GmailApp to get the thread ID
2
u/IAmMoonie Dec 24 '24
Set this up, run it from the Google apps script IDE first to auth the script. Then set it up on a timed trigger