Track your finances from your Gmail inbox 📧.
- Parses emails from Gmail using the Gmail API.
- Extracts finance details based on configurable regex patterns.
- Supports multiple email patterns and categories.
- A Google Sheets template is provided to help you get started.
- Go Environment: Ensure Go is installed on your system.
- Google API Credentials: Place your
client_secret.jsonfile in the.config/email-spending-tracker/creds/directory. - Configuration File: Update the
config.yamlfile with your email patterns and Google Sheets details.
- Google Sheets:
spreadsheetId: The ID of your Google Sheets document.range: The range in the spreadsheet where data will be appended.
- Emails:
address: The email address to parse.patterns:pattern: The regex pattern to match in the email body.category: The category for the transaction (e.g., "Expense", "Income").useSnippet: If true, use the email snippet instead of the full email body.
View an example config file in config.yaml.example.
These options are useful for finding & testing your patterns:
-dry-run: Enable dry-run mode (no changes will be made).-email: Specify an email address to fetch emails for (requires-dry-run).-days: Number of days to look back for emails (default: 10).-snippet: Use email snippets instead of full emails.
Suppose you want to track credit card payments from noreply@yourbank.com.
-
Fetch emails from the address:
./build/email-spending-tracker -dry-run -email noreply@yourbank.com -snippet
- This will get snippets for all emails from
noreply@yourbank.comover the last 7 days. - You can remove the
-snippetflag if the full email body is needed. - Add the
-daysflag to configure the number of days to look back.
- This will get snippets for all emails from
-
Once you've identified the email from step 1, create a pattern that matches the email body.
- The pattern should have only one capture group for the amount.
- See Configuration and config.yaml.example
-
Test the pattern:
./build/email-spending-tracker -dry-run
Make a copy of the Google Sheets template.
- If you use this template as is, please remove the example data first.
- Also make sure to update the
spreadsheetIdin the config file with the ID of your new spreadsheet.
-
Install dependencies:
go get ./...
-
Build the application:
go build -o build/email-spending-tracker
-
Run the application:
./build/email-spending-tracker
-
[Optional] Setup a cron job:
crontab -e
Add the following line to run the script every day at midnight:
0 0 * * * <path/to/app>
Or, if you want to save the logs:
0 0 * * * <path/to/app> >> <path/to/log_file> 2>&1
- Dates from the Gmail API are in CDT (6 hours behind UTC).
- The
date_filter.txtfile stores the last processed date in the formatyyyy/mm/dd hh:mm:ss.