Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Anthropic research says AI can mass expose of anonymous internet accounts

    Phone-based system promises better avatar movement without expensive VR gear

    Terminator-inspired liquid metal tech promises better eyes for robots and cars

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      What the polls say about how Americans are using AI

      February 27, 2026

      Tensions between the Pentagon and AI giant Anthropic reach a boiling point

      February 21, 2026

      Read the extended transcript: President Donald Trump interviewed by ‘NBC Nightly News’ anchor Tom Llamas

      February 6, 2026

      Stocks and bitcoin sink as investors dump software company shares

      February 4, 2026

      AI, crypto and Trump super PACs stash millions to spend on the midterms

      February 2, 2026
    • Business

      Google releases Gemini 3.1 Flash Lite at 1/8th the cost of Pro

      March 4, 2026

      Huawei Watch GT Series

      March 4, 2026

      Weighing up the enterprise risks of neocloud providers

      March 3, 2026

      A stolen Gemini API key turned a $180 bill into $82,000 in two days

      March 3, 2026

      These ultra-budget laptops “include” 1.2TB storage, but most of it is OneDrive trial space

      March 1, 2026
    • Crypto

      Banks Respond to Kraken’s Federal Reserve Access as Trump Sides with Crypto

      March 4, 2026

      Hyperliquid and DEXs Break the Top 10 — Is the CEX Era Ending?

      March 4, 2026

      Consensus Hong Kong 2026: The Institutional Turn 

      March 4, 2026

      New Crypto Mutuum Finance (MUTM) Reports V1 Protocol Progress as Roadmap Enters Phase 3

      March 4, 2026

      Bitcoin Short Sellers Caught Off Guard in New White House Move

      March 4, 2026
    • Technology

      Anthropic research says AI can mass expose of anonymous internet accounts

      March 7, 2026

      Phone-based system promises better avatar movement without expensive VR gear

      March 7, 2026

      Terminator-inspired liquid metal tech promises better eyes for robots and cars

      March 7, 2026

      Sony may push ahead with PS6 despite rising component costs

      March 7, 2026

      Today’s NYT Strands Hints, Answers and Help for March 8 #735

      March 7, 2026
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Gmail to SQLite
    Technology

    Gmail to SQLite

    TechAiVerseBy TechAiVerseMay 10, 2025No Comments4 Mins Read5 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Gmail to SQLite
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Gmail to SQLite

    Gmail to SQLite

    This is a script to download emails from Gmail and store them in a SQLite database for further analysis. I find it extremely useful to have all my emails in a database to run queries on them. For example, I can find out how many emails I received per sender, which emails take the most space, and which emails from which sender I never read.

    Installation

    1. Clone this repository: git clone https://github.com/marcboeker/gmail-to-sqlite.git.
    2. Install the requirements: pip install -r requirements.txt
    3. Create a Google Cloud project here.
    4. Open Gmail in API & Services and activate the Gmail API.
    5. Open the OAuth consent screen and create a new consent screen. You only need to provide a name and contact data.
    6. Next open Create OAuth client ID and create credentials for a Desktop app. Download the credentials file and save it under credentials.json in the root of this repository.

    Here is a detailed guide on how to create the credentials: https://developers.google.com/gmail/api/quickstart/python#set_up_your_environment.

    Usage

    Sync all emails

    1. Run the script: python main.py sync --data-dir path/to/your/data where -- is the path where all data is stored. This creates a SQLite database in /messages.db and stores the user credentials under /credentials.json.
    2. After the script has finished, you can query the database using, for example, the sqlite3 command line tool: sqlite3 /messages.db.
    3. You can run the script again to sync all new messages. Provide --full-sync to force a full sync. However, this will only update the read status, the labels, and the last indexed timestamp for existing messages.

    Sync a single message

    python main.py sync-message --data-dir path/to/your/data --message-id

    Commandline parameters

    usage: main.py [-h] [--data-dir DATA_DIR] [--update] {sync, sync-message}
    
    Main commands:
    sync                    Sync emails from Gmail to the database.
    sync-message            Sync a single message from Gmail to the database.
    
    --data-dir DATA_DIR     Path to the directory where all data is stored.
    --full-sync             Force a full sync.
    --message-id MESSAGE_ID Sync only the message with the given message id.
    

    Schema

    CREATE TABLE IF NOT EXISTS "messages" (
        "id" INTEGER NOT NULL PRIMARY KEY, -- internal id
        "message_id" TEXT NOT NULL, -- Gmail message id
        "thread_id" TEXT NOT NULL, -- Gmail thread id
        "sender" JSON NOT NULL, -- Sender as JSON in the form {"name": "Foo Bar", "email": "foo@example.com"}
        "recipients" JSON NOT NULL, -- JSON object: {
          -- "to": [{"email": "foo@example.com", "name": "Foo Bar"}, ...],
          -- "cc": [{"email": "foo@example.com", "name": "Foo Bar"}, ...],
          -- "bcc": [{"email": "foo@example.com", "name": "Foo Bar"}, ...]
        --}
        "labels" JSON NOT NULL, -- JSON array: ["INBOX", "UNREAD", ...]
        "subject" TEXT NOT NULL, -- Subject of the email
        "body" TEXT NOT NULL, -- Extracted body either als HTML or plain text
        "size" INTEGER NOT NULL, -- Size reported by Gmail
        "timestamp" DATETIME NOT NULL, -- When the email was sent/received
        "is_read" INTEGER NOT NULL, -- 0=Unread, 1=Read
        "is_outgoing" INTEGER NOT NULL, -- 0=Incoming, 1=Outgoing
        "last_indexed" DATETIME NOT NULL -- Timestamp when the email was last seen on the server
    );

    Example queries

    Get the number of emails per sender

    Show the number of unread emails by sender

    This is great to determine who is spamming you the most with uninteresting emails.

    Get the number of emails for a specific period

    • For years: strftime('%Y', timestamp)
    • For months in a year: strftime('%m', timestamp)
    • For days in a month: strftime('%d', timestamp)
    • For weekdays: strftime('%w', timestamp)
    • For hours in a day: strftime('%H', timestamp)

    SELECT strftime('%Y', timestamp) AS period, COUNT(*) AS count
    FROM messages
    GROUP BY period
    ORDER BY count DESC

    Find all newsletters and group them by sender

    This is an amateurish way to find all newsletters and group them by sender. It’s not perfect, but it’s a start. You could also use

    Show who has sent the largest emails in MB

    Count the number of emails that I have sent to myself

    List the senders who have sent me the largest total volume of emails in megabytes

    Roadmap

    • Detect deleted emails and mark them as deleted in the database.
    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleVision Now Available in Llama.cpp
    Next Article How cloud and AI transform and improve customer experiences
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Anthropic research says AI can mass expose of anonymous internet accounts

    March 7, 2026

    Phone-based system promises better avatar movement without expensive VR gear

    March 7, 2026

    Terminator-inspired liquid metal tech promises better eyes for robots and cars

    March 7, 2026
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025705 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025291 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 2025166 Views

    6 Best MagSafe Phone Grips (2025), Tested and Reviewed

    April 6, 2025125 Views
    Don't Miss
    Technology March 7, 2026

    Anthropic research says AI can mass expose of anonymous internet accounts

    Anthropic research says AI can mass expose of anonymous internet accounts New research involving scientists…

    Phone-based system promises better avatar movement without expensive VR gear

    Terminator-inspired liquid metal tech promises better eyes for robots and cars

    Sony may push ahead with PS6 despite rising component costs

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Anthropic research says AI can mass expose of anonymous internet accounts

    March 7, 20262 Views

    Phone-based system promises better avatar movement without expensive VR gear

    March 7, 20262 Views

    Terminator-inspired liquid metal tech promises better eyes for robots and cars

    March 7, 20262 Views
    Most Popular

    7 Best Kids Bikes (2025): Mountain, Balance, Pedal, Coaster

    March 13, 20250 Views

    VTOMAN FlashSpeed 1500: Plenty Of Power For All Your Gear

    March 13, 20250 Views

    Best TV Antenna of 2025

    March 13, 20250 Views
    © 2026 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.