I'm having issue trying to loop through an email inbox. I was previously able to use what I had written, but since reinstalling ExchangeLib I'm now throwing an error. Here is what I have so far.
from exchangelib import Credentials, Account
from bs4 import BeautifulSoup
credentials = Credentials('my@email', 'password')
account = Account('my@email', credentials=credentials, autodiscover=True)
my_inbox = account.inbox
for item in my_inbox.all()[:1]:
html = item.unique_body
soup = BeautifulSoup(html, "html.parser")
for span in soup.find_all('font'):
return(item.subject, item.sender.email_address, span.text)
print(item.subject, item.sender.email_address, span.text)
What I'm hoping to be able to do is to access my inbox, and return the subject line, sender email, and body text from the first email (had to put it through BeautifulSoup because item.unique_body is all HTML tags). But is currently printing nothing. I have the print statement there as a test, but will remove it when it is working.
Also, I keep getting an error that reads "Method 'inbox' has no 'all' member, referencing my_inbox.all()
. I also don't know why that isn't working since it was working the other day.
Any help?