Email Digest Generator

Automatically summarize newsletters, industry news, and team updates into concise digests.

This workflow aggregates emails, extracts key points, and generates personalized summaries.

Implementation

1import { relay } from "@relayplane/workflows";
2
3const result = await relay
4 .workflow("email-digest")
5
6 // Step 1: Extract key information from each email
7 .step("extract-emails")
8 .with("openai:gpt-4o")
9 .prompt(`Extract key information from these emails:
10
11{{emailBatch}}
12
13For each email, extract:
14- Sender and subject
15- Main topic/theme
16- Key points (max 3 per email)
17- Action items or deadlines
18- Priority level (high/medium/low)
19
20Skip promotional content and automated notifications.
21Return as JSON array.`)
22
23 // Step 2: Categorize by topic
24 .step("categorize")
25 .with("anthropic:claude-3.5-sonnet")
26 .depends("extract-emails")
27 .prompt(`Categorize these emails by topic:
28
29{{extract-emails.output}}
30
31Categories:
32- Industry News
33- Product Updates
34- Team Announcements
35- Customer Feedback
36- Technical Discussions
37- Administrative
38
39Group related emails together.
40Return categorized structure.`)
41
42 // Step 3: Generate summary
43 .step("generate-summary")
44 .with("anthropic:claude-3.5-sonnet")
45 .depends("categorize")
46 .prompt(`Create a concise email digest:
47
48{{categorize.output}}
49
50Format:
51# Daily Digest - {{date}}
52
53## 🔥 Requires Action
54- Items with deadlines or requests
55
56## 📰 Industry News
57- Key trends and announcements
58
59## 💼 Team Updates
60- Internal announcements
61
62## 💡 Worth Reading
63- Interesting insights
64
65Keep each section to 3-5 bullet points.
66Total length: under 300 words.
67Include links to original emails.`)
68
69 .run({
70 emailBatch: emails.map(e => ({
71 from: e.from,
72 subject: e.subject,
73 body: e.textContent.slice(0, 1000), // First 1000 chars
74 receivedAt: e.date,
75 })),
76 date: new Date().toLocaleDateString(),
77 });
78
79// Send digest
80await sendEmail({
81 to: user.email,
82 subject: `Your Daily Digest - ${new Date().toLocaleDateString()}`,
83 html: markdownToHTML(result.steps["generate-summary"].output),
84});

Gmail Integration

1import { google } from 'googleapis';
2import { relay } from "@relayplane/workflows";
3
4async function dailyDigest() {
5 const gmail = google.gmail({ version: 'v1', auth: oAuth2Client });
6
7 // Fetch unread emails from last 24 hours
8 const response = await gmail.users.messages.list({
9 userId: 'me',
10 q: 'is:unread newer_than:1d',
11 maxResults: 50,
12 });
13
14 const emails = [];
15 for (const msg of response.data.messages || []) {
16 const full = await gmail.users.messages.get({
17 userId: 'me',
18 id: msg.id,
19 format: 'full',
20 });
21
22 emails.push({
23 from: getHeader(full, 'From'),
24 subject: getHeader(full, 'Subject'),
25 body: extractTextBody(full),
26 date: getHeader(full, 'Date'),
27 });
28 }
29
30 // Generate digest
31 const digest = await relay
32 .workflow("email-digest")
33 .run({
34 emailBatch: emails,
35 date: new Date().toLocaleDateString(),
36 });
37
38 return digest.steps["generate-summary"].output;
39}
40
41// Schedule for 8am daily
42cron.schedule('0 8 * * *', dailyDigest);

Advanced Filtering

1// Custom filters
2const result = await relay
3 .workflow("email-digest")
4 .step("extract-emails")
5 .with("openai:gpt-4o")
6 .prompt(`Extract key info from emails:
7
8{{emailBatch}}
9
10FILTERS:
11- Exclude: automated CI/CD notifications, marketing emails
12- Prioritize: emails from leadership, customer escalations
13- Flag: any mentions of "urgent", "deadline", "asap"
14
15For each relevant email, extract key points.`)
16 .step("generate-summary")
17 .with("anthropic:claude-3.5-sonnet")
18 .depends("extract-emails")
19 .run({ emailBatch: emails });

Sample Output

# Daily Digest - Nov 18, 2025 ## 🔥 Requires Action - **Sarah (Product)**: Review Q4 roadmap by EOD Friday - **Customer Success**: Enterprise client requesting demo of new features - **IT Security**: Complete security training by Nov 25 ## 📰 Industry News - OpenAI releases GPT-5 with extended context window (128k tokens) - New EU AI regulation impacts enterprise deployments - Anthropic announces Claude 4 with improved reasoning ## 💼 Team Updates - Engineering shipped v3.2 with performance improvements - Sales hit 125% of monthly target - New hire starting Monday: Alex Chen (DevOps) ## 💡 Worth Reading - Thoughtful piece on AI safety from DeepMind - Case study: How Stripe uses AI for fraud detection

Customization

  • Add sentiment analysis to flag urgent/negative emails
  • Integration with Slack for channel digests
  • Personalized summaries based on user role
  • Weekly rollup instead of daily