# Turn starred Gmail emails into a Mem knowledge base

> Every 30 minutes during your workday, starred Gmail messages become clean, searchable Mem notes filed into the right collection.

- Workflow type: agent
- Services: Gmail, Mem
- Categories: Personal Productivity, Operations
- Published: 2026-07-02

## What it does

- Sweeps your Gmail every 30 minutes and grabs anything you have starred since the last run.
- Saves each starred email into Mem as a tidy markdown note with the subject as the title, sender and date up top, and a short AI summary above the cleaned message body.
- Files the note into the Mem collection that best matches the topic, and spins up a new collection when nothing fits.
- Skips anything already saved, so re-runs never create duplicates and your starred inbox turns into a real knowledge base.

## What you'll need

- A Gmail account you can connect (personal or Google Workspace).
- A Mem account with an API key from Settings, API in the Mem web app.
- A working habit of starring the emails you want to remember.

## Prompt

Build me an agent workflow that turns my starred Gmail emails into a clean, searchable Mem knowledge base.

Trigger: cron, every 30 minutes during my working hours (default Mon–Fri, 8am to 7pm in my local timezone). I want this expressed as a schedule the platform can actually run, since Gmail is not a first-class poll trigger.

Two integrations, both first-class: Gmail (List Messages, Get a Message, Modify Message Labels, and Create a Label if the label does not exist yet) and Mem (Search Notes, Create Note, List Collections, and Create Collection when needed).

On each run the agent should do the following, in order:

1. Make sure a Gmail user label called "Saved-to-Mem" exists. If Get a Label / List Labels does not find it, call Create a Label to make it. Cache the label id for the rest of the run.

2. Call Gmail List Messages with the query is:starred -label:Saved-to-Mem to get the candidate message ids. Page through results only if there are more than can be handled in one run; a reasonable per-run cap (say 25 messages) is fine so we do not blow the Mem complexity quota.

3. For each candidate message, call Gmail Get a Message with format=full to pull the subject, sender, date, RFC-822 Message-ID header, and the message body. Prefer text/plain; fall back to text/html and strip tags to clean markdown.

4. Dedupe defensively. Call Mem Search Notes for the Gmail message id (the RFC-822 Message-ID header value, not the Gmail thread id). If a note already exists that references that id, skip creating a new note and jump straight to the labeling step below. This protects against a Saved-to-Mem label that failed to write on a previous run.

5. Pick a Mem collection. Call Mem List Collections once per run and cache it. For each email, match the best collection by comparing sender domain, subject keywords, and a short AI-generated topic guess to existing collection titles and descriptions. If nothing scores a reasonable match, call Mem Create Collection with a clean, human name (project name, client name, or topic) and use that.

6. Call Mem Create Note. The note content is markdown. Mem uses the first line as the title, so start with '# {subject}'. Then a small metadata block: 'From: {sender name} <{email}>', 'Date: {ISO date}', 'Gmail Message-ID: {rfc822 id}', and a link back to the Gmail thread. Follow that with a two-to-four-sentence AI summary under a '## Summary' heading, then the cleaned message body under a '## Body' heading. Attach the note to the chosen collection via the create-note collections field. Preserve any inline links from the email.

7. Call Gmail Modify Message Labels to add the Saved-to-Mem label to that message id. This is what keeps the next run's List Messages query from re-processing the same email.

Error handling: if Create Note fails, do not label the Gmail message; let the next run retry. If Modify Message Labels fails after a successful Create Note, log it but do not create a second note next run because step 4's Search Notes dedupe will catch it. Respect Mem's rate limits (100 requests/min, 200 complexity tokens/min): if you hit a 429, back off for the Retry-After duration and continue.

Output: at the end of the run, produce a short internal summary (how many messages were swept, how many notes created, which collections they landed in, any skips or errors). No email or Slack recap needed. No em dashes anywhere in the copy the agent writes.

## How to customize

- Change the schedule. Every 30 minutes during working hours is the default, but you can go hourly, twice a day, or only on weekdays.
- Pick a different Gmail signal. Swap starring for a specific label, an importance marker, or a saved search like emails from your VCs.
- Tune the note format. Add a tag list, drop the AI summary, or route certain senders into a dedicated collection like Clients or Research.

## FAQ

### Will the same email get saved twice if I star it, unstar it, and star it again?

No. Once an email is saved to Mem, the workflow adds a Saved-to-Mem label in Gmail and only looks for starred messages that do not already have that label, so every message is filed exactly once.

### Can I use a different Gmail signal instead of starring?

Yes. Starring is the default because it is one keystroke, but you can switch the filter to any Gmail search, like emails with a specific label, from a specific sender, or matching a saved search.

### How does the workflow decide which Mem collection an email belongs in?

It reads your existing Mem collections and matches on the email's topic, sender, and subject. If nothing fits, it creates a new collection with a sensible name and files the note there.

### Does this work with a Google Workspace inbox?

Yes. Any Gmail account you can sign into, personal or Google Workspace, works the same way.

### What ends up in the note itself?

A markdown note with the email subject as the title, then sender, date, and a short AI-written summary, followed by the cleaned message body. It is optimized for searching and re-reading later, not for looking like an email.

Use this prompt in General Input: https://www.generalinput.com/prompts/turn-starred-gmail-emails-into-a-mem-knowledge-base