Gmail logger - log your google account in 2023

Gmail logger - log your google account in 2023

I found this GitHub repository with a Python script that helps you log metadata about your Gmail inbox.

https://github.com/mddub/gmail-logger

I read the manual and replicate it.

Installation

Clone the repository with this command:

git clone [email protected]:mddub/gmail-logger.git

Add a file called secret.py , which looks like this.

email = '[email protected]'
password = 'your_app_password'

Google app password

You probably have a Google account with 2-step verification, so you need to create a new app password for this.

  • Go to your Google account

  • Open the Security tab and find a block "Signing in to Google."

  • Click on the second option, "App passwords."

  • On the next page, you need to "Select the app and device for which you want to generate the app password." and click Generate password button

  • You will see a new password that you have to copy and add to the secret.py file. If you close this window, you will not see this password anymore, so you need to generate another one.

Python environment

Make sure you have "pip" and "virtualenv" installed on your machine.

You need to set up a virtualenv, activate it, and install the requirements:

virtualenv venv
. venv/bin/activate
pip install -r requirements.txt

Once you have done it, please test it out:

python log_inbox.py

To schedule it to run regularly you can use crontab which schedules it every hour:

0 * * * * cd /path/to/log/to; /path/to/gmail-logger/venv/bin/python /path/to/gmail-logger/log_inbox.py >/dev/null

Reporting Output

If you were to run it hourly, inbox_count.log would look something like this:

1664363664	2022-09-28 11:14:24	48
1664367264	2022-04-28 12:14:24	49
...

Every hour, a JSON file named something like 2022-09-28_11.14.24.json would be produced:

[
  {
    "date": "Mon, 28 Mar 2022 11:14:24 +0900",
    "thread_id": "1497103965428563028",
    "unread": false,
    "from": [
      "Donald Trump <[email protected]>"
    ],
    "subject": "Hi Rus, how are you doing?"
  },
  ...
]

Related video

FAQs

What is Gmail logger?

Gmail logger is a Python script that helps you log metadata about your Gmail inbox.

Where can I find Gmail logger?

You can find Gmail logger on GitHub repository.

How can I install Gmail logger?

Clone the repository with the command: git clone [email protected]:mddub/gmail-logger.git. Then, add a file called secret.py and follow the instructions in the blog post.

How can I create an app password for Gmail logger?

You need to go to your Google account, open the Security tab, find the 'Signing in to Google' block, click on 'App passwords', and follow the instructions to generate a new app password.

What Python environment do I need to use Gmail logger?

Make sure you have 'pip' and 'virtualenv' installed on your machine.

How can I test if Gmail logger works?

Once you have set up the virtualenv and installed the requirements, run the command 'python log_inbox.py' to test it out.

How can I schedule Gmail logger to run regularly?

You can use crontab to schedule it to run every hour. Follow the instructions in the blog post.

What is the output of Gmail logger?

The output includes a log file named inbox_count.log and a JSON file with the metadata of your Gmail inbox.

How can I view the JSON file produced by Gmail logger?

The JSON file is produced every hour with a timestamp in the file name. You can open it with a text editor or use a JSON viewer to view the contents.

Related articles

Ruslan Osipov
Author: Ruslan Osipov