Hello. I have a python code that I want to delete an email with specific subject.But I get an error.What should i do?
Error:
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.12) or chardet (3.0.4) doesn't match a supported version!
warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
File "__carClicker__.py", line 753, in <module>
read_TXT_FILE_from_gmail()
File "__carClicker__.py", line 214, in read_TXT_FILE_from_gmail
mail.store(mail_ids , '+FLAGS', '(\\Trash)')
File "/usr/lib/python3.8/imaplib.py", line 842, in store
typ, dat = self._simple_command('STORE', message_set, command, flags)
File "/usr/lib/python3.8/imaplib.py", line 1205, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/usr/lib/python3.8/imaplib.py", line 963, in _command
data = data + b' ' + arg
TypeError: can't concat list to bytes
Here is the code:
What I have tried:
global FROM_EMAIL , FROM_PWD
mail = imaplib.IMAP4_SSL(SMTP_SERVER)
mail.login(FROM_EMAIL , FROM_PWD)
mail.select('inbox')
data = mail.search(None, 'ALL')
mail_ids = data[1]
id_list = mail_ids[0].split()
latest_email_id = int(id_list[-1])
check_last_N_emails = 11
for e in range(latest_email_id , latest_email_id - check_last_N_emails , -1):
data = mail.fetch(str(e), '(RFC822)' )
for response_part in data:
arr = response_part[0]
if isinstance(arr, tuple):
msg = email.message_from_string(str(arr[1],'utf-8'))
email_subject = msg['subject']
email_from = msg['from']
for part in msg.walk():
filename__ = part.get_filename()
if filename__:
open(PATH_NAME + str(filename__) , "wb").write(part.get_payload(decode=True))
if(not "20 errors occured" in email_subject):
now = datetime.datetime.now()
if(email_subject == "update" or email_subject == "Update"):
mail.store(mail_ids , '+FLAGS', '(\\Trash)')
This is a function.I use it to do other things too.
I think the mistake here is the last command.
Thanks for your help.