0

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)
Vladimir
  • 6,162
  • 2
  • 32
  • 36
Sooplis
  • 1
  • 2
  • Show examples. Python str is utf8, msg.subject - utf8 – Vladimir Sep 30 '22 at 04:44
  • the question needs sufficient code for a minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – D.L Oct 01 '22 at 11:54
  • That is the entire code, can't be more especific than that. But to be clear, if the subject have accents, returns an ascii error. If has no accents works fine. – Sooplis Oct 01 '22 at 13:29

0 Answers0