0

I'm trying to download a word document attachment from my Gmail account using imbox in Python, but when I decode the attachment I get a bunch of unreadable bytes (utf-8 won't decode them, and they are mostly null bytes). Does Imbox just not work with .doc files?

Here's my code:

# Downloads Word document schedule from my emails

# Imports
import os
from imbox import Imbox


# Logging in
host = "imap.gmail.com"  # Gmail
emailUser = "my.email@gmail.com"  # My account
emailPass = os.environ.get("MailPass")  # My password

mail = Imbox(host, username=emailUser, password=emailPass, ssl=True, ssl_context=None, starttls=False)  # Connecting
messages = mail.messages(sent_from="example.sender@gmail.com")  # Getting messages from schedule sender

for uid, message in messages:

    if message.attachments:
        attachment = message.attachments
        for idx, att in enumerate(attachment):
            att.get('content').read()
        break

martineau
  • 119,623
  • 25
  • 170
  • 301
linguini
  • 44
  • 4

0 Answers0