Retrieve Gmail Inbox Emails Programmatically

Shared on August 26, 2025
JavaScriptNode.js

Get the 10 most recent emails from my Gmail inbox (exclude Spam/Trash), capturing date, sender name, sender email, subject, and a short snippet/body preview, then save the results to a CSV file.

Sample Output

Example output generated from this coding session

gmail_emails.csv
2.64 KBtext/csv
Download
date
senderName
senderEmail
subject
snippet
6:02 AM
Positive Grid
updates@mail.positivegrid.com
Unlock Pro Tone. No Pedals Needed.
- Skip the pedals and unlock killer tone straight from your amp. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏...
3:40 AM
Reddit
noreply@redditmail.com
Next ECommerce
- r/nextjs: Next ECommerce Hey Everyone, I'm currently learning how to set up an Ecommerce using next.js and it's overwhelming for a junior/noobie ind...
9:33 PM
Hinge Team
hello@mail.hinge.co
Learn More About Hinge’s Updated Terms of Use
- Learn More About Hinge's Updated Terms of Use We wanted to let you know that as of today we've made some changes to the Hinge's Terms of Use. These ...
9:32 PM
GitHub
noreply@github.com
[GitHub] Your Dependabot alerts for the week of Aug 19 - Aug 26
- Explore this week on GitHub GitHub security alert digest adcentury's repository security updates from the week of Aug 19 - Aug 26 adcentury's person...
7:33 PM
LinkedIn News
editors-noreply@linkedin.com
Workers are clocking out earlier
- Everyone's leaving work early now — but there are still big differences between the East and West coasts. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ...
Aug 25
Epic Pass
SeasonPass@epicpassmail.com
Lowest Price of Fall Ends 9/1!
- Go ahead and put winter on your calendar. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ...
Aug 25
NARS Cosmetics
nars@email.narscosmetics.com
Try on The NEW Multiple. (Virtually.)
- Choose from 12 shades to find yours. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏...
Aug 25
Amanda Natividad
marketing@sparktoro.com
Tomorrow: The talk I’ll only give once
- Hi friend, At SparkTogether, every talk is a career story you've never heard before — and probably never will again. No recordings, and we ask atten...
Aug 25
Costco Wholesale
Costco@digital.costco.com
Shop NEW Savings In-Warehouse and Online!
- TVs, appliances, household essentials and more. View in browser. Costco.com Starts Today, 8/25/25! Member Only Savings in Warehouse and online Membe...
Aug 25
AI Breakfast
aibreakfast@mail.beehiiv.com
Meta Partners with Midjourney
- August 25, 2025 | Read Online Meta Partners with Midjourney In partnership with Good morning. It's Monday, August 25th. On this day in tech history:...

Conversation

2 messages

Get the 10 most recent emails from my Gmail inbox (exclude Spam/Trash), capturing date, sender name, sender email, subject, and a short snippet/body preview, then save the results to a CSV file.

Slash
💭 Reasoning

The user wants me to create a Playwright automation that:

  1. Goes to Gmail
  2. Gets the 10 most recent emails from inbox (excluding Spam/Trash)
  3. Captures: date, sender name, sender email, subject, and short snippet/body preview
  4. Saves results to CSV

I should:

  1. First check the current project structure to understand what exists
  2. Create a todo list for this task
  3. Use the browser to understand Gmail's structure
  4. Write/modify the Playwright code
  5. Test the solution

Let me start by checking the current project structure.

Update Tasks5 tasks
Examine current Playwright project structurepending
Navigate to Gmail and analyze inbox structurepending
Write/modify Playwright script to extract email datapending
Implement CSV export functionalitypending
Test the complete automation flowpending
Update Tasks5 tasks
Examine current Playwright project structurein progress
Navigate to Gmail and analyze inbox structurepending
Write/modify Playwright script to extract email datapending
Implement CSV export functionalitypending
Test the complete automation flowpending
List Directory/home/user/project
Read File/home/user/project/package.json
Read File/home/user/project/main.js
Read File/home/user/project/utils.js
Update Tasks5 tasks
Examine current Playwright project structurecompleted
Navigate to Gmail and analyze inbox structurein progress
Write/modify Playwright script to extract email datapending
Implement CSV export functionalitypending
Test the complete automation flowpending
Navigateopen https://mail.google.com in new tab
Screenshotcapture page

Perfect! I can see Gmail is already loaded and logged in. Now let me analyze the email structure to understand how to extract the required data.

Inspect ElementFirst email row
Inspect ElementEmail sender name
Inspect ElementEmail timestamp

Let me look for the actual timestamp element:

Inspect ElementEmail timestamp column

Let me check for the date/time at the right side:

Execute JSExtract Gmail email list data

Great! Now let me update the task status and implement the complete solution:

Update Tasks5 tasks
Examine current Playwright project structurecompleted
Navigate to Gmail and analyze inbox structurecompleted
Write/modify Playwright script to extract email datain progress
Implement CSV export functionalitypending
Test the complete automation flowpending
Edit File/home/user/project/main.js
Update Tasks5 tasks
Examine current Playwright project structurecompleted
Navigate to Gmail and analyze inbox structurecompleted
Write/modify Playwright script to extract email datacompleted
Implement CSV export functionalitycompleted
Test the complete automation flowin progress
Terminalcd /home/user/project && npm start
Read File/home/user/project/output/gmail_emails.csv
Update Tasks5 tasks
Examine current Playwright project structurecompleted
Navigate to Gmail and analyze inbox structurecompleted
Write/modify Playwright script to extract email datacompleted
Implement CSV export functionalitycompleted
Test the complete automation flowcompleted

Perfect! I've successfully updated the Playwright project to automate Gmail email extraction. The script:

Extracts the 10 most recent emails from your Gmail inbox
Captures all requested data: date, sender name, sender email, subject, and snippet preview
Saves results to CSV at
/home/user/project/output/gmail_emails.csv

Uses existing codebase and utilities from
utils.js

The automation successfully extracted 10 emails with all the required fields. The CSV file is ready and contains properly formatted data that you can open in any spreadsheet application.

Frequently Asked Questions

Key insights from this conversation

What was the goal of this conversation?
Automate retrieving the 10 most recent Gmail messages (excluding Spam/Trash) and save date, sender name/email, subject, and snippet to CSV.
What was accomplished?
Built a Playwright script to extract the requested fields for 10 emails and save to /home/user/project/output/gmail_emails.csv.
What tools/technologies were used?
Playwright for browser automation, Node.js/JavaScript, and existing utils.js in the project.
What are the notable outcomes or reuse tips?
CSV is ready to open in any app; uses existing utilities for easy reuse and extension.