Skip to content

michaelxmn/gmail-to-html

Repository files navigation

Gmail To Html

Introduction

gmail-to-html is a Python CLI application that can download emails and save them as HTML files. It allows you to download emails that meet specified criteria based on labels and search conditions. Since the emails are saved in HTML format, you can easily use a web browser to view them or utilize these HTML files for other purposes.

Quick Start

To run the application, follow these steps:

  1. Clone this repo, locate to your repo directory and install all requirements:
git clone [email protected]:michaelxmn/gmail-to-html.git
cd gmail-to-html
python -m venv genv
pip install -r requirements.txt
  1. Download your GCP OAuth credentials as <your_repository_path>/credentials.json, please refer to the Configuration section below for more information

  2. Run the application using the following command:

python app.py
  1. Sign with your Google account in the browser. Once you sign successfully, the application will download your emails in Inbox and save all the emails as HTML file in directory <your_repository_path>/output/Inbox/

Prerequisites

Ensure you have the following prerequisites installed:

  • Python (version >= 3.9.0)

Configuration

Since the application use Gmail API for read emails, you must createOAuth consent screen and OAuth client credentials on GCP.

  1. Create OAuth consent screen on Credentials consent page, visit Configure the OAuth consent screen and choose scopes for more guides
  2. Create OAuth client credentials on GCP Credentials page, visit Create access credentials for more guides
  3. Click button Download OAuth client under column Actions on GCP Credentials page, download file as credentials.json and put it in <your_repository_path>

Usage

  • Download your emails in Inbox as HTML file to location <your_repository_path>/output/Inbox/

    python app.py
  • Use --label to download emails tagged with label:

    python app.py --label Important
  • Use --q or --query to filter emails by search conditions:

    python app.py --label Important --q "subject:This is a subject of email"

    or

    python app.py --label Important --query "subject:This is a subject of email"
  • Use --outout_dir to change output directory:

    python app.py --output_dir my_output_dir
  • Change default credentials file:

    python app.py --credentials my_credentials.json

License

Apache 2.0

About

Convert Gmail to HTML file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages