I've been trying to print email body using python(using imap_tools lib)but it's not really working for me. here is the code snippet.
from imap_tools import MailBox, A, AND, OR, NOT
with MailBox('outlook.office365.com').login('test@test.com', 'test') as mailbox:
for msg in mailbox.fetch(A(seen=False)):
print(msg.text)
but when I print the subject using msg.subject
, it's working fine. I tried using msg.html and here is the output.
<body lang="EN-IN" link="blue" vlink="#954F72" style="word-wrap:break-word"><div class="WordSection1"><p class="MsoNormal">Hi, this is a test email to store body in file<o:p></o:p></p></div></body></html>
note: this is not the whole HTML output, but this is to show that the email has some data in the body. Can anyone help me solve this problem?