I'm using python imap_tools to login on gmail and download it's attachments from specific emails.
It was suposed to fetch by subject and a date, but subject is returning an error. The code works as expected when i use body instead of subject. The command line to print msg subject is working as well.
The problem is: i'm using a subject in utf-8 and the subject atribute only accepts ascii, returning an ascii error. How to covert a subject with accents (utf-8) to ascii in the code below?
Thanks in advance.
with MailBox('imap.gmail.com').login('myadress@gmail.com', 'password', 'INBOX') as mailbox:
for msg in mailbox.fetch(AND(subject='Email subject', date=date.today())):
print(msg.subject)
for att in msg.attachments:
with open('C:Downloads{}'.format(att.filename), 'wb') as f:
f.write(att.payload)