DEV Community

Cover image for Autonomous Email Summarization
Stanley J
Stanley J

Posted on • Originally published at istealersn.substack.com

Autonomous Email Summarization

Building an Autonomous Email Summarization Workflow with n8n, AI, and Obsidian

How I built a daily automation that fetches financial newsletters, summarizes them with AI, and saves clean markdown notes to Obsidian - completely hands-free.

The Problem

Like many investors, I receive daily market newsletters packed with valuable insights. But who has time to read through lengthy emails every morning? I wanted an automation that could:

  • Fetch emails automatically from specific senders
  • Extract and clean the content
  • Generate intelligent summaries using AI
  • Save formatted notes to my knowledge management system
  • Run completely autonomous - no manual intervention needed

The Solution Architecture

After exploring various approaches, I settled on this tech stack:

  • 🕐 n8n: Workflow automation and orchestration
  • 📧 Gmail API: Email fetching with smart filtering
  • 🤖 Groq: Free AI summarization (Llama models)
  • 📝 Obsidian: Knowledge management with Local REST API
  • ⚙️ PM2: Process management for 24/7 operation

Step 1: Setting Up the Daily Trigger

The foundation is a schedule trigger that runs every day at 9:15 AM. This timing ensures I get summaries of yesterday’s emails right when I start my day.

// Cron expression for 9:15 AM IST daily
Schedule Trigger: 15 9 * * *
Timezone: Asia/Kolkata
Enter fullscreen mode Exit fullscreen mode

Key insight: Always set the timezone explicitly to avoid confusion when testing vs production.

Step 2: Smart Email Filtering

Rather than processing all emails repeatedly, I implemented dynamic date filtering:

// Only fetch emails from last 24 hours
Received After: {{ new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString() }}
Sender: specific-newsletter@domain.com
Enter fullscreen mode Exit fullscreen mode

This ensures:

  • Only new emails are processed daily
  • No duplicate processing
  • Efficient API usage
  • Relevant, timely content

Step 3: Email Content Extraction

Gmail API returns emails in a complex nested structure. The key was handling both plain text and HTML emails while cleaning up the content:

// Extract email body from Gmail's complex structure
function extractBody(emailData) {
  let from = 'Unknown Sender';
  if (emailData.from && emailData.from.value && emailData.from.value[0]) {
    const sender = emailData.from.value[0];
    from = sender.name ? `${sender.name} <${sender.address}>` : sender.address;
  }

  // Extract subject and date from emailData
  const subject = emailData.subject || 'No Subject';
  const date = emailData.date || new Date().toISOString();

  // Prioritize plain text, fallback to cleaned HTML
  let emailBody = '';
  if (emailData.text && emailData.text.trim().length > 0) {
    emailBody = emailData.text;
  } else if (emailData.textAsHtml) {
    emailBody = emailData.textAsHtml
      .replace(/<p>/g, '\n')
      .replace(/<\/p>/g, '')
      .replace(/<br\s*\/?>/g, '\n')
      .replace(/&nbsp;/g, ' ')
      .replace(/<[^>]*>/g, '')
      .trim();
  }

  return { subject, from, date, emailBody };
}
Enter fullscreen mode Exit fullscreen mode

Lesson learned: Always handle multiple email formats and include robust text cleaning for better AI processing.

Step 4: AI-Powered Summarization

For AI summarization, I chose Groq for its generous free tier (14,400 requests/day) and fast inference. The key was crafting prompts specifically for financial content:

Individual Summary Prompt:
Analyze and summarize this financial newsletter content focusing on:

"{text}"

Provide a CONCISE SUMMARY that includes:
- Key stock recommendations and target prices
- Important market insights and trends  
- Sector analysis and opportunities
- Risk factors or warnings mentioned
- Actionable investment advice
- Any time-sensitive information

Format the summary in clear bullet points for easy reading.
Enter fullscreen mode Exit fullscreen mode

Pro tip: Customize your AI prompts for your specific domain. Generic summarization prompts don’t capture domain-specific insights effectively.

Step 5: Obsidian Integration Challenge

This is where things got interesting. I initially tried Obsidian’s Local REST API:

// HTTP Request to Obsidian Local REST API
Method: PUT
URL: https://127.0.0.1:27124/vault/VaultName/filename.md
Headers: Authorization: Bearer <API_KEY>
Body: Markdown content
Enter fullscreen mode Exit fullscreen mode

The Problem: Obsidian API returns HTTP 204 “No Content” on successful file creation, which n8n’s HTTP Request node can’t parse properly, causing server log errors.

The n8n HTTP 204 Bug

After extensive debugging, I discovered this is a known limitation in n8n:

  • File gets created successfully in Obsidian
  • Workflow completes and functions correctly
  • Server logs show parsing errors due to empty response body

The research revealed:

  • Multiple GitHub issues (#11283)
  • Community forum requests for better 204 handling
  • This affects many APIs that return 204 responses

Current workarounds:

  • Enable “Never Error” option
  • Enable “Include Response Headers and Status”

  • Accept the log noise (functionality works fine)

Step 6: Production Deployment with PM2

Running automation workflows requires 24/7 operation. PM2 was the perfect solution:

# Install PM2
npm install -g pm2

# Start n8n as a service
pm2 start n8n --name "n8n-automation"

# Set up auto-start on boot
pm2 startup
pm2 save
Enter fullscreen mode Exit fullscreen mode

Benefits of PM2:

  • Auto-restart on crashes
  • Survives system reboots
  • Runs independently of user sessions
  • Built-in logging and monitoring
  • No need for VSCode or browser to stay open

The Final Workflow

Here’s what runs every morning at 9:15 AM:

  1. Schedule Trigger → Wakes up the workflow
  2. Gmail Node → Fetches new emails from specific sender
  3. Code Node → Extracts and cleans email content
  4. Summarization Chain → AI-powered content analysis
  5. HTTP Request → Creates formatted markdown in Obsidian

Output: Clean, formatted daily notes like:

---
date: 2025-07-29T14:30:00.000Z
source: Financial Newsletter
type: Email Summary
---

# Daily Email Summary - July 29, 2025

## Original Email Details
- **From**: Newsletter Name <sender@domain.com>
- **Subject**: Daily Market Analysis
- **Date**: 2025-07-29T09:15:00.000Z

## AI Summary

**Top Stock Recommendations:**
- Company A (BUY) - Strong Q1 results
- Company B (HOLD) - Mixed earnings outlook

**Market Insights:**
- Tech sector showing resilience
- Energy stocks under pressure due to...

---
*Generated automatically at 14:30 IST*
Enter fullscreen mode Exit fullscreen mode

Key Learnings

What Worked Well:

  • Modular approach: Each step handles one responsibility
  • Smart filtering: Date-based filtering eliminates duplicate processing
  • Free AI tier: Groq’s generous limits make this cost-effective
  • Local integration: Direct file creation in knowledge management system

Challenges Overcome:

  • Gmail API complexity: Nested email structures require careful parsing
  • n8n HTTP limitations: 204 response handling is currently buggy
  • Production deployment: Moving from development to 24/7 operation
  • Content cleaning: Raw email HTML needs significant processing

Future Improvements:

  • Multiple email sources: Expand to other newsletter subscriptions
  • Content categorization: Use AI to tag and organize summaries
  • Trend analysis: Weekly/monthly rollups of key themes
  • Alert system: Notify on high-priority market events

Cost Breakdown

Monthly Operating Costs: ~$0

  • n8n: Free (self-hosted)
  • Gmail API: Free tier sufficient
  • Groq AI: Free tier (14,400 requests/day)
  • Obsidian: Local storage
  • Mac Mini: Already owned

Time Investment:

  • Initial setup: ~4 hours
  • Maintenance: ~5 minutes/month
  • Daily time saved: ~15 minutes

ROI: After 2 weeks, the automation pays for itself in time savings.

Technical Considerations

Security:

  • API keys stored in n8n’s encrypted credential system
  • Local-only processing (no cloud data exposure)
  • HTTPS with certificate validation for all external calls

Reliability:

  • PM2 ensures 99%+ uptime
  • Error handling for network issues
  • Graceful degradation when services are unavailable

Scalability:

  • Easy to add new email sources
  • AI processing handles variable content lengths
  • File system can grow indefinitely

Conclusion

Building this automation transformed my morning routine. Instead of manually reading through lengthy financial newsletters, I now get concise, AI-generated summaries delivered directly to my knowledge management system.

The technical journey revealed interesting challenges around email parsing, AI prompt engineering, and n8n’s HTTP handling limitations. But the end result is a robust, autonomous system that saves significant time daily.

Total setup time: 4 hours

Daily time saved: 15 minutes

Monthly maintenance: 5 minutes

Technical satisfaction: Immeasurable 😊

Next Steps

If you’re inspired to build something similar:

  1. Start simple: Begin with one email source and basic summarization
  2. Test thoroughly: Run manually several times before automating
  3. Handle edge cases: Empty emails, API failures, network issues
  4. Monitor initially: Watch logs for the first week to catch issues
  5. Iterate: Add features gradually based on actual usage

The combination of n8n’s visual workflow builder, modern AI APIs, and local knowledge management creates powerful possibilities for personal automation.


Have you built similar automation workflows? What challenges did you face and how did you solve them? Share your experiences in the comments below!

About Me

Engineering Leader with a decade of experience building scalable frontend architectures for high-traffic applications. Specialized in headless CMS implementations, performance optimization, and developer experience tooling. Currently architecting content delivery systems that serve millions of users while maintaining exceptional developer productivity.

Passionate about sharing real-world engineering lessons learned from production deployments, code reviews, and the inevitable 2 AM debugging sessions that teach us the most.

Connect with me:

Follow for more insights on frontend architecture, headless CMS patterns, and battle-tested engineering practices that actually work in production.


Have an optimization story or trick that worked wonders? Drop it in the comments or tag me on your platform of choice. Let’s keep learning from each other.

Top comments (0)