cd /news/ai-tools/ai-powered-email-agent-that-syncs-yoโ€ฆ ยท home โ€บ topics โ€บ ai-tools โ€บ article
[ARTICLE ยท art-111531] src=github.com โ†— pub= topic=ai-tools verified=true sentiment=ยท neutral

AI-powered email agent that syncs your emails via IMAP

EmailAI, an open-source Go-based email agent, syncs emails via IMAP and uses AI from OpenAI, Anthropic, or local Ollama to summarize, categorize, and extract insights, with support for SMTP sending and full-text search. The tool, available on GitHub, requires Go 1.21 or higher and an IMAP-enabled email account, and it stores emails locally as JSON for easy backup and inspection.

read5 min views1 publishedAug 26, 2026
AI-powered email agent that syncs your emails via IMAP
Image: Michielbdejong (auto-discovered)

An AI-powered email agent that syncs your emails via IMAP and provides intelligent analysis using OpenAI, Anthropic, or local Ollama.

๐Ÿ”„ IMAP Sync- Mirror your email account locally with batch syncing๐Ÿ‘๏ธ IDLE Support- Real-time email detection (when server supports it)๐Ÿค– AI Analysis- Summarize, categorize, and extract insights from emails๐Ÿ“ค SMTP Send- Send replies generated by AI๐Ÿ” Search- Full-text search across all synced emails๐Ÿ“ฆ Local Storage- Emails stored as JSON, easy to inspect and backup๐Ÿ”ง Configurable- Works with Gmail, Outlook, or any IMAP server

  • Go 1.21 or higher
  • An email account with IMAP access enabled
  • (Optional) AI API key for smart features
git clone https://github.com/peterretief/emailai.git
cd emailai

go build -o emailai .

go install github.com/peterretief/emailai@latest
cp config.example.json config.json

nano config.json
{
  "imap": {
    "host": "imap.gmail.com",
    "port": 993,
    "username": "you@gmail.com",
    "password": "your-app-password",
    "tls": true
  },
  "smtp": {
    "host": "smtp.gmail.com",
    "port": 587,
    "username": "you@gmail.com",
    "password": "your-app-password",
    "tls": true
  }
}

Choose one of the supported AI providers:

OpenAI:

{
  "ai": {
    "enabled": true,
    "provider": "openai",
    "api_key": "sk-your-key-here",
    "model": "gpt-4"
  }
}

Anthropic:

{
  "ai": {
    "enabled": true,
    "provider": "anthropic",
    "api_key": "sk-ant-your-key-here",
    "model": "claude-3-opus-20240229"
  }
}

Ollama (Local, free):

Install Ollama from https://ollama.com, then pull a local model:

ollama pull llama3.1:8b

Make sure the Ollama server is running:

ollama serve

Configure EmailAI to use the local model:

{
  "ai": {
    "enabled": true,
    "provider": "ollama",
    "api_key": "",
    "model": "llama3.1:8b",
    "max_tokens": 2048
  }
}

Good free local model choices include llama3.1:8b

, qwen2.5:7b

, and mistral:7b

. For email analysis and structured extraction, qwen2.5:7b

is also worth trying:

ollama pull qwen2.5:7b

Then set ai.model

to qwen2.5:7b

.

./emailai -action sync

./emailai -action sync -folder INBOX

./emailai -action sync -full-sync

./emailai -action serve

./emailai -action analyze -query "meeting"

./emailai -action contacts -limit 100

./emailai -action stats

./emailai -action search -folder INBOX -query "driver licence"

./emailai -action search -folder INBOX -attach jpg -query "driver licence"

./emailai -action send

For large Gmail mailboxes, increase the batch size in config.json

so each sync run imports more messages:

{
  "sync": {
    "maildir_path": "",
    "store_path": "./emails",
    "max_batch_size": 1000
  }
}

Run sync repeatedly until each folder is up to date:

while ./emailai -action sync; do sleep 10; done

Press Ctrl+C

to stop the loop.

emailai/
โ”œโ”€โ”€ main.go              # Entry point and CLI
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ config.go        # Configuration management
โ”œโ”€โ”€ sync/
โ”‚   โ””โ”€โ”€ sync.go          # IMAP sync engine
โ”œโ”€โ”€ store/
โ”‚   โ””โ”€โ”€ store.go         # Local email storage
โ”œโ”€โ”€ ai/
โ”‚   โ””โ”€โ”€ ai.go            # AI processing (OpenAI/Anthropic/Ollama)
โ”œโ”€โ”€ smtp/
โ”‚   โ””โ”€โ”€ smtp.go          # Email sending
โ”œโ”€โ”€ config.example.json  # Example configuration
โ””โ”€โ”€ README.md
Option Description Default
imap.host
IMAP server hostname imap.gmail.com
imap.port
IMAP server port 993
imap.username
Email address -
imap.password
App password -
imap.tls
Use TLS encryption true
smtp.host
SMTP server hostname smtp.gmail.com
smtp.port
SMTP server port 587
ai.enabled
Enable AI features false
ai.provider
AI provider (openai , anthropic , ollama )
openai
ai.model
Model to use gpt-4
sync.interval
Sync interval in seconds 300
sync.folders
Folders to sync (empty = all) []
sync.max_batch_size
Max emails per sync batch 100
sync.store_path
Local storage path ./emails
sync.timeout_seconds
Maximum time for one IMAP command 120
sync.maildir_path
Local Maildir root managed by mbsync/isync empty
filters.exclude_newsletters
Exclude matching newsletter/marketing emails from local search and analyze results false
filters.exclude_from
Sender substrings to exclude when newsletter filtering is enabled newsletter/no-reply/etc.
filters.exclude_subject
Subject substrings to exclude when newsletter filtering is enabled newsletter/digest/etc.
filters.exclude_body
Body substrings to exclude when newsletter filtering is enabled unsubscribe/etc.
ocr.enabled
Run local OCR on image attachments false
ocr.command
OCR executable tesseract
ocr.languages
Tesseract language list eng
ocr.timeout_seconds
Maximum OCR runtime per image 60
ocr.max_bytes
Maximum image size sent to OCR 10485760

When ocr.enabled

is true, image attachments are processed locally with Tesseract during sync. Extracted text is stored in the local email JSON and included in search. Attachment image bytes are not stored by the OCR feature.

Normal syncs store a per-folder IMAP UID watermark and fetch only newer messages. Use -full-sync

to rescan every message, for example after enabling OCR or changing message parsing.

Set filters.exclude_newsletters

to true

to keep obvious newsletters, promotions, and automated bulk mail out of search

and analyze

results. Tune the exclude_from

, exclude_subject

, and exclude_body

lists for your mailbox.

To use mbsync

/isync

for mailbox synchronization, set sync.maildir_path

to the Maildir root. When this is configured, the application reads local Maildir files and does not connect to IMAP. Run mbsync

first, then run ./emailai -action sync

to import new messages and process OCR.

Contributions are welcome! Please feel free to submit a Pull Request.

  • Fork the repository
  • Create your feature branch ( git checkout -b feature/amazing-feature

) - Commit your changes ( git commit -m 'Add amazing feature'

) - Push to the branch ( git push origin feature/amazing-feature

) - Open a Pull Request

This project is licensed under the MIT License - see the LICENSE file for details.

  • Never commit your config.json

file (it's in.gitignore

) - Use App Passwords, not your regular email password

  • Keep your AI API keys secure
  • The emails/

directory contains your synced emails - treat it as sensitive data

go-imap- IMAP library for Gogo-imap-idle- IDLE extensiongo-message- Email message parsing

If you have any questions or issues, please open an issue on GitHub.

โ”€โ”€ more in #ai-tools 4 stories ยท sorted by recency
โ”€โ”€ more on @emailai 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain โ€” perfect for shipping the agent you just read about.

$git push zahid main
โ†’ Live at https://your-agent.zahid.host โœ“
Get free account โ†’ Pricing
from โ‚ฌ0/mo ยท no card required
LIVE [news/ai-powered-email-ageโ€ฆ] indexed:0 read:5min 2026-08-26 ยท โ€”