Jay Jen
Jay Jen

Reputation: 745

How can I display email messages in Tkinter?

I've been writing an email application in python/tkinter, where I download the messages from my gmail then display them in a window.

The problem I keep getting though is that most messages contain html and come out as gibberish.

Is there any way properly display the emails in tkinter, maybe without the pictures, in a way which doesn't come out as loads of html code etc. I've tried html2text but this doesn't work for all emails and still displays them pretty badly (big gaps between words etc)?

Thanks

Upvotes: 0

Views: 611

Answers (1)

Malik Brahimi
Malik Brahimi

Reputation: 16721

You can use BeautifulSoup assuming you have the HTML data and an id corresponding to the element in which the message body is contained. Please let me know if that doesn't make sense.

from bs4 import *

soup = BeautifulSoup(html_data_in_here)
text = soup.find(id = body_id).getText()

Upvotes: 2

Related Questions