0

I've searched for this topic at length and could not find an exact answer. Hope I can get some guidance here.

I would like to read emails from my email Inbox (say Gmail or any email endpoint), and for each email I want to figure out if it is in HTML format or plain text.

  • For HTML emails, I'd like to extract some data and metadata (like sender, subject, terms within email etc), replace a few things, then save the email in an HTML file, such that it can be opened in a browser with layout, images and links intact. So when I open that html file, the entire email content renders properly as it did in my email inbox.

  • For text email, I'd like to extract similar metadata, replace a few things and then save in a text file. So that when opened, the content of email are shown in the text file without any email headers.

I've looked at Beautiful Soup and some other libraries. I can't figure how to save the email in files while keeping their html intact that renders properly.

Appreciate any help. Thanks in advance!

Zee Kay
  • 73
  • 1
  • 5

1 Answers1

0

I made a simple custom button in the past that adds an image to a message if I click the button. There are ways to get the metadata using the same technique. You might then be able to interact with this extension with Python once you learn more about the API.

A custom button would be found in Gmail > Settings > Add-Ons > Installed developer add-ons:, once installed.

This will give you a good start. You can find examples online.

https://developers.google.com/apps-script/add-ons/guides/using-addons

I suppose if one were clever, you could take a screenshot with a Windows app, written in C++ (Microsoft has this code available), then use OCR to read the data from outside Chromium.

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245