diff --git a/workflows/Create AI-Summarized Email Digests from Gmail Labels with OpenAI O4-Mini-5839/readme-5839.md b/workflows/Create AI-Summarized Email Digests from Gmail Labels with OpenAI O4-Mini-5839/readme-5839.md new file mode 100644 index 000000000..0a10f8be3 --- /dev/null +++ b/workflows/Create AI-Summarized Email Digests from Gmail Labels with OpenAI O4-Mini-5839/readme-5839.md @@ -0,0 +1,308 @@ +Create AI-Summarized Email Digests from Gmail Labels with OpenAI O4-Mini + +https://n8nworkflows.xyz/workflows/create-ai-summarized-email-digests-from-gmail-labels-with-openai-o4-mini-5839 + + +# Create AI-Summarized Email Digests from Gmail Labels with OpenAI O4-Mini + +### 1. Workflow Overview + +This workflow automates the creation and sending of a daily email digest containing AI-generated summaries of emails labeled in a Gmail account. It is designed to help users efficiently consume multiple emails from specific categories (such as newsletters or news feeds) by summarizing their content into concise, well-formatted HTML digests. The workflow runs on a daily schedule, fetches emails from the last 24 hours under a specific Gmail label, processes each email with OpenAI's "o4-mini" model to generate summaries, combines these summaries, and sends the digest as one consolidated email. + +Logical blocks: + +- **1.1 Scheduled Email Retrieval:** Trigger the workflow daily, fetch labeled emails from Gmail received in the last 24 hours, and conditionally proceed if emails exist. +- **1.2 AI-Powered Email Summarization:** Process email content using LangChain nodes with OpenAI’s "o4-mini" chat model, including document loading, text splitting, and summarization chains. +- **1.3 Content Formatting and Email Delivery:** Extract key fields, combine all summaries into a single HTML digest with structured headings, and send the digest via Gmail. +- **1.4 Conditional Processing:** Skip summarization and sending if no emails are found to avoid empty digests. + +--- + +### 2. Block-by-Block Analysis + +#### 1.1 Scheduled Email Retrieval + +**Overview:** +Runs daily at 9 AM, retrieves up to 20 emails from a specified Gmail label received in the last 24 hours, and filters the flow based on availability of emails. + +**Nodes Involved:** +- Schedule Trigger +- Get mails (last 24h) +- If +- No Operation, do nothing + +**Node Details:** + +- **Schedule Trigger** + - Type: Core Trigger + - Role: Starts workflow daily at 9:00 AM + - Config: Interval trigger set to trigger at 9 AM every day + - Inputs: None + - Outputs: Connects to "Get mails (last 24h)" + - Edge cases: Workflow only triggers at scheduled time; no fallback for missed runs. + +- **Get mails (last 24h)** + - Type: Gmail node + - Role: Fetch emails with a specific Gmail label received in the last 24 hours + - Config: + - Limit: 20 emails + - Filters: Label IDs set to `YOUR_LABEL_ID` (user must replace with actual label) + - Received after: dynamic expression for current time minus 1 day + - Operation: getAll (fetch all matching emails up to limit) + - Inputs: From Schedule Trigger + - Outputs: Connects to "If" node + - Requirements: Gmail OAuth2 credentials configured + - Edge cases: Invalid label ID or authentication failure; no emails found. + +- **If** + - Type: Conditional node + - Role: Checks if any emails were retrieved (length > 0) + - Config: Condition: number of items greater than 0 + - Inputs: From "Get mails (last 24h)" + - Outputs: + - True: proceeds to "Summarization Mails" + - False: proceeds to "No Operation, do nothing" + - Edge cases: Expression evaluation failures; empty email list. + +- **No Operation, do nothing** + - Type: NoOp node + - Role: Terminates workflow path gracefully if no emails found + - Inputs: From "If" (false branch) + - Outputs: None + - Edge cases: None + +--- + +#### 1.2 AI-Powered Email Summarization + +**Overview:** +Processes each retrieved email’s content by loading it as a document, splitting the text optimally, and feeding it through a summarization chain powered by OpenAI's "o4-mini" chat model with a custom prompt that generates HTML summaries preserving external links. + +**Nodes Involved:** +- OpenAI Chat Model +- Recursive Character Text Splitter +- Default Data Loader +- Summarization Mails + +**Node Details:** + +- **OpenAI Chat Model** + - Type: LangChain AI Language Model node + - Role: Provides access to OpenAI’s "o4-mini" chat model for text generation + - Config: Model set to "o4-mini" (optimized smaller model) + - Inputs: Connected as ai_languageModel input to "Summarization Mails" + - Outputs: AI-generated summaries + - Credentials: OpenAI API key required + - Edge cases: API rate limits, authentication errors, model errors. + +- **Recursive Character Text Splitter** + - Type: LangChain Text Splitter node + - Role: Splits email text recursively into chunks sized to the whole text length (effectively no splitting) + - Config: Chunk size set dynamically to the length of the email text (disables splitting) + - Inputs: From "Summarization Mails" (ai_textSplitter input) + - Outputs: Passes split text to "Default Data Loader" + - Edge cases: Large text may cause timeouts or memory issues. + +- **Default Data Loader** + - Type: LangChain Document Data Loader node + - Role: Loads the JSON email text into a document format for processing + - Config: Uses dynamic expression to load text from email JSON field `text` + - Inputs: From "Recursive Character Text Splitter" (ai_document input) + - Outputs: Document passed to "Summarization Mails" + - Edge cases: Missing or malformed text field. + +- **Summarization Mails** + - Type: LangChain Summarization Chain node + - Role: Executes summarization on loaded documents using OpenAI chat model and a detailed prompt + - Config: + - Summarization method: "stuff" (concatenate all texts) + - Prompt includes instructions for: + - Concise summaries + - Bullet points for multiple topics + - Preservation and numbering of external links in HTML format + - Output formatted with `

`, `