Opening Problem Statement
Meet Sarah, a busy freelancer who spends hours every week sorting through her inbox looking for expense receipts. She manually downloads attachments, extracts data, and enters the details into a Google Sheet to track her budget. This tedious process wastes about 3-4 hours weekly and often leads to errors like missed items or incorrect totals, costing her both time and money during tax season.
If only there was a way to automatically pull those expense details from her emails and organize them neatly without manual effort. That’s exactly where this n8n workflow shines — by transforming how Sarah handles her expense tracking.
What This Automation Does
This workflow listens to incoming emails, identifies those containing receipts or expenses, extracts the key information from the receipt attachments, formats the extracted data, and appends it directly to a designated Google Sheet. Here’s what happens when this automation runs:
- Automatically checks Sarah’s Gmail Inbox for new emails with receipt or expense keywords in the subject line.
- Extracts expense details like date, category, currency, and total amount from receipt attachments using Mindee’s AI-powered OCR service.
- Formats the extracted data into relevant columns for easy tracking (Date, Description, Category, Currency, Amount).
- Appends the formatted expense data into Sarah’s Google Sheets expense tracker for seamless financial management.
- Saves Sarah multiple hours each week by removing manual entry and reduces errors in her expense records.
- Allows Sarah to easily review and analyze her expenses anytime from her well-organized spreadsheet.
Prerequisites ⚙️
- Gmail Account for IMAP access 📧: To allow the workflow to read emails and attachments from Sarah’s Gmail Inbox.
- Mindee Receipt API account 🔐: For intelligent extraction of data from receipt image attachments.
- Google Sheets Account 📊: To store the extracted expense details in a structured spreadsheet.
- n8n Account & Instance ⏱️: To build, run and maintain the automation workflow. You can self-host if preferred (see Host your own instance).
Step-by-Step Guide
Step 1: Set Up Email Retrieval from Gmail
In n8n, add an EmailReadImap node.
- Navigate to Nodes → EmailReadImap.
- Configure the node to use your Gmail IMAP credentials (make sure to enable “Allow Unauthorized Certs” if needed).
- Set the mailbox to “Inbox” to scan all incoming emails.
- Go to Nodes → Set and add it after EmailReadImap node.
- In this node, create a string variable called
subjectPatternsand set its value to(expenses|reciept)— note the intentional misspelling “reciept” to catch common variations. - Setup a condition where the email subject (converted to lowercase) matches the regular expression stored in
subjectPatterns. - Use the string condition type with regex operation to filter emails that contain keywords like “expenses” or “reciept” in the subject.
- Connect this node to run only on emails that passed the subject filter.
- Set the parameter
binaryPropertyNametoattachment_0assuming the receipt is the first attachment. - Enter your Mindee API credentials to allow automatic receipt data extraction.
- Map fields from the Mindee node JSON output to match your Google Sheets columns:
- Date =>
{{$json["date"]}} - Description => Extracted from the email subject splitting by “-” and taking the second part (e.g. “Expense – Uber”)
- Category =>
{{$json["category"]}} - Currency =>
{{$json["currency"]}} - Amount =>
{{$json["total"]}} - Select the appropriate Google Sheets Spreadsheet ID (e.g.,
1xAtx1ORZYKu4urgqpOe3DawFjiWeOZO0VCVvOlQYnaE). - Set the range to
A:Eto cover the columns Date, Description, Category, Currency, and Amount. - Use OAuth2 authentication to securely connect your Google Sheets.
- Change Subject Keyword Filter: Update the Setup Variables node’s
subjectPatternsvalue to include other keywords like “invoice” or “bill” to process different email types. - Process Multiple Attachments: Modify the Mindee Receipt node to process
attachment_1or other attachments if receipts are not always the first one. - Add Expense Tax Calculation: Insert a Function or Code node after extracting data to automatically compute tax from the total before adding to the sheet.
- Send Notification on New Entry: Add an email or Slack node post-Google Sheets append to notify Sarah of new expenses added.
- Update Sheet Range Dynamically: Change the Google Sheets node range parameter to auto-select columns based on headers for scalability.
- Verify Gmail IMAP settings and credentials.
- Test Mindee API connection and validate receipt images are accessible.
- Confirm Google Sheets Spreadsheet ID and OAuth2 credentials have edit rights.
- Run workflow on sample emails to ensure data flows correctly through the nodes.
- Backup important sheets or create a duplicate before running live automation.
Visual check: You should see emails listed with metadata including subject lines once the node executes.
Common Mistake: Not enabling IMAP in your Gmail settings will cause emails not to load.
Step 2: Define Subject Patterns to Identify Receipt Emails
Add a Set node named Setup Variables.
This variable tells the workflow which email subjects to focus on for further processing.
Step 3: Filter Emails Based on Subject Using the If Node
Insert an If node named Check subject.
Expected result: Only emails matching the criteria continue through the workflow.
Common Mistake: Forgetting to convert the email subject to lowercase or misconfiguring the regex will cause skipping relevant emails.
Step 4: Extract Receipt Data from Email Attachments with Mindee Node
Add the Mindee Receipt node.
Behind the scenes: This node uses Mindee’s AI to read receipt images and output structured data like total amount, currency, date, and category.
Common Mistake: If attachments are missing or not named properly, the node might fail. Verify email attachments before running.
Step 5: Format Extracted Data into Sheet Columns
Add another Set node named Set column data.
This formatting ensures your spreadsheet rows are clean and consistent.
Common Mistake: Misalignment of field names or typos in variable references will cause empty cells in your spreadsheet.
Step 6: Append Data to Google Sheets
Add the Google Sheets node configured to append data.
Expected outcome: New rows with extracted expenses are added automatically after each matching email is processed.
Common Mistake: Incorrect Sheet ID or range will cause appends to fail silently.
Customizations ✏️
Troubleshooting 🔧
Problem: “Emails not appearing in the EmailReadImap node output.”
Cause: IMAP access not enabled or incorrect credentials.
Solution: Go to Gmail settings → Forwarding and POP/IMAP → Enable IMAP. Reconfigure credentials in n8n with correct username and password.
Problem: “Mindee node returns error or empty data.”
Cause: Missing or corrupted receipt attachments.
Solution: Check if emails have attachments properly loaded and verify binaryPropertyName points to the right attachment index.
Problem: “Google Sheets append operation fails silently.”
Cause: Incorrect Sheet ID or missing permissions.
Solution: Confirm Sheet ID from the Google Sheets URL, ensure OAuth2 credentials have access to edit the sheet.
Pre-Production Checklist ✅
Deployment Guide
Once you verify all nodes work correctly, activate your workflow in the n8n editor by toggling the “Active” switch on the top right. This enables real-time monitoring and automatic execution every time a new email arrives matching the criteria.
Regularly monitor the execution log in n8n for failures. Adjust thresholds or error handling as needed. Consider setting up alerts or notifications for errors by extending the workflow with alert nodes.
Conclusion
By setting up this n8n workflow, you’ve automated the tedious process of extracting expense receipt details from emails and adding them directly to Google Sheets. This saves Sarah at least 3 hours per week on manual data entry and minimizes costly errors in expense tracking.
Next, consider automating invoice processing or integrating with your accounting software to further streamline financial management. The possibilities with n8n’s powerful integrations are endless!