Last active
September 5, 2022 12:16
Revisions
-
viperadnan-git revised this gist
Apr 23, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ - To delete all unread email, replace line 10 with `typ, data = box.search(None, 'UnSeen') or set value of query to `UnSeen` ##### Run snippet with python Use python3.8.0 or older. ```sh python3 delete_email.py ``` -
viperadnan-git revised this gist
Apr 23, 2021 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,10 @@ ##### Configure What to delete - Default it will delete all email which contains `Custom String` in subject. Change it in line 5. - To delete all email from a specific sender, replace line 10 with `typ, data = box.search(None, 'from', 'specific@sender.email')` - To delete all unread email, replace line 10 with `typ, data = box.search(None, 'UnSeen') or set value of query to `UnSeen` ##### Run snippet with python Use python3.8.0 ```sh puthone delete_email.py ``` -
viperadnan-git created this gist
Apr 23, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #### Delete Junk Emails from you Gmail Account easily with python. ##### Generate Mail App Password - Visit <https://support.google.com/accounts/answer/185833> for full guide. - Select `Mail` in App and `Other` in Device ##### Configure What to delete - Default it will delete all email which contains `Custom String` in subject. Change it in line 5. - To delete all email from a specific sender, replace line 10 with `typ, data = box.search(None, 'from', 'specific@sender.email')` - To delete all unread email, replace line 10 with `typ, data = box.search(None, 'UnSeen') or set value of query to `UnSeen` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import imaplib GmailId = "YourUsername@gmail.com" AppPassword = "YourAppPassword" query = r'(X-GM-RAW "subject:\"Custom String\"")' box = imaplib.IMAP4_SSL('imap.gmail.com', 993) box.login(GmailId, AppPassword) box.select('Inbox') typ, data = box.search(None, query) count = 0 for num in data[0].split(): box.store(num, '+FLAGS', '\\Deleted') count += 1 box.expunge() box.close() box.logout() print(f"Deleted {count} junk emails successfully")