Marcus Romano
Marcus Romano

Reputation: 1

Getting text on imap_tools with python only able for fowarded e-mail

I’ve developed a Python script using imap_tools to retrieve billing information sent to my email.

However, some companies include the necessary information only in the body of the email. In some cases, I can extract this information using the imap_tools.text attribute, but other times it doesn’t work. Interestingly, if I manually forward the email to myself, the information becomes readable using imap_tools.text.

  1. Is there a way to automatically retrieve this information?

  2. Alternatively, does anyone know how to set up an automatic email forwarding (not resending) in Gmail?

Here's my code:

def get_mailbox(folder: str = None) -> mailbox:
    mails = mailbox.MailBox('imap.gmail.com')
    return mails.login(username='[email protected]',
                       password='password,
                       initial_folder=folder)

def get_emails_from_folder(folder: str):
    caixa_emails = get_mailbox(folder=folder)
    return list(caixa_emails.fetch(AND(seen=False)))

emails = get_emails_from_folder('Billings')
    if not emails:
        return {}
    for email in emails:
        text = email.text

Thanks in advance!

Upvotes: 0

Views: 20

Answers (1)

Vladimir
Vladimir

Reputation: 6726

At lib docs:

Email has 2 basic body variants: text and html. Sender can choose to include: one, other, both or neither(rare).

lib athor.

Upvotes: 0

Related Questions