Reputation: 1
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.
Is there a way to automatically retrieve this information?
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
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