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.
To run the application, follow these steps:
- 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
-
Download your GCP OAuth credentials as
<your_repository_path>/credentials.json
, please refer to the Configuration section below for more information -
Run the application using the following command:
python app.py
- 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/
Ensure you have the following prerequisites installed:
- Python (version >= 3.9.0)
Since the application use Gmail API for read emails, you must createOAuth consent screen
and OAuth client credentials
on GCP.
- Create OAuth consent screen on Credentials consent page, visit Configure the OAuth consent screen and choose scopes for more guides
- Create OAuth client credentials on GCP Credentials page, visit Create access credentials for more guides
- Click button
Download OAuth client
under columnActions
on GCP Credentials page, download file ascredentials.json
and put it in <your_repository_path>
-
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
Apache 2.0