forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_emails.py
More file actions
Latest commit
18 lines (16 loc) · 675 Bytes
/
Copy pathdelete_emails.py
File metadata and controls
18 lines (16 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fromcommonimportgmail_authenticate, search_messages
defdelete_messages(service, query):
messages_to_delete=search_messages(service, query)
# it's possible to delete a single message with the delete API, like this:
# service.users().messages().delete(userId='me', id=msg['id'])
# but it's also possible to delete all the selected messages with one query, batchDelete
returnservice.users().messages().batchDelete(
userId='me',
body={
'ids': [ msg['id'] formsginmessages_to_delete]
}
).execute()
if__name__=="__main__":
importsys
service=gmail_authenticate()
delete_messages(service, sys.argv[1])