{"slug": "ai-powered-email-agent-that-syncs-your-emails-via-imap", "title": "AI-powered email agent that syncs your emails via IMAP", "summary": "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.", "body_md": "An AI-powered email agent that syncs your emails via IMAP and provides intelligent analysis using OpenAI, Anthropic, or local Ollama.\n\n**🔄 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\n\n- Go 1.21 or higher\n- An email account with IMAP access enabled\n- (Optional) AI API key for smart features\n\n```\n# Clone the repository\ngit clone https://github.com/peterretief/emailai.git\ncd emailai\n\n# Build\ngo build -o emailai .\n\n# Or install directly\ngo install github.com/peterretief/emailai@latest\n# Copy the example config\ncp config.example.json config.json\n\n# Edit with your settings\nnano config.json\n```\n\n- Enable 2-Step Verification at\n[https://myaccount.google.com/security](https://myaccount.google.com/security) - Generate an App Password at\n[https://myaccount.google.com/apppasswords](https://myaccount.google.com/apppasswords) - Use the 16-character app password (not your regular password)\n\n```\n{\n  \"imap\": {\n    \"host\": \"imap.gmail.com\",\n    \"port\": 993,\n    \"username\": \"you@gmail.com\",\n    \"password\": \"your-app-password\",\n    \"tls\": true\n  },\n  \"smtp\": {\n    \"host\": \"smtp.gmail.com\",\n    \"port\": 587,\n    \"username\": \"you@gmail.com\",\n    \"password\": \"your-app-password\",\n    \"tls\": true\n  }\n}\n```\n\nChoose one of the supported AI providers:\n\n**OpenAI:**\n\n```\n{\n  \"ai\": {\n    \"enabled\": true,\n    \"provider\": \"openai\",\n    \"api_key\": \"sk-your-key-here\",\n    \"model\": \"gpt-4\"\n  }\n}\n```\n\n**Anthropic:**\n\n```\n{\n  \"ai\": {\n    \"enabled\": true,\n    \"provider\": \"anthropic\",\n    \"api_key\": \"sk-ant-your-key-here\",\n    \"model\": \"claude-3-opus-20240229\"\n  }\n}\n```\n\n**Ollama (Local, free):**\n\nInstall Ollama from [https://ollama.com](https://ollama.com), then pull a local model:\n\n```\nollama pull llama3.1:8b\n```\n\nMake sure the Ollama server is running:\n\n```\nollama serve\n```\n\nConfigure EmailAI to use the local model:\n\n```\n{\n  \"ai\": {\n    \"enabled\": true,\n    \"provider\": \"ollama\",\n    \"api_key\": \"\",\n    \"model\": \"llama3.1:8b\",\n    \"max_tokens\": 2048\n  }\n}\n```\n\nGood free local model choices include `llama3.1:8b`\n\n, `qwen2.5:7b`\n\n, and `mistral:7b`\n\n. For email analysis and structured extraction, `qwen2.5:7b`\n\nis also worth trying:\n\n```\nollama pull qwen2.5:7b\n```\n\nThen set `ai.model`\n\nto `qwen2.5:7b`\n\n.\n\n```\n# Sync all emails\n./emailai -action sync\n\n# Sync specific folder\n./emailai -action sync -folder INBOX\n\n# Force a complete rescan when needed\n./emailai -action sync -full-sync\n\n# Run as continuous sync server\n./emailai -action serve\n\n# Analyze emails with AI\n./emailai -action analyze -query \"meeting\"\n\n# List contacts found in downloaded mail\n./emailai -action contacts -limit 100\n\n# View sync stats\n./emailai -action stats\n\n# Search email text and locally extracted OCR text\n./emailai -action search -folder INBOX -query \"driver licence\"\n\n# Restrict the search to image attachments\n./emailai -action search -folder INBOX -attach jpg -query \"driver licence\"\n\n# Send test email\n./emailai -action send\n```\n\nFor large Gmail mailboxes, increase the batch size in `config.json`\n\nso each sync run imports more messages:\n\n```\n{\n  \"sync\": {\n    \"maildir_path\": \"\",\n    \"store_path\": \"./emails\",\n    \"max_batch_size\": 1000\n  }\n}\n```\n\nRun sync repeatedly until each folder is up to date:\n\n```\nwhile ./emailai -action sync; do sleep 10; done\n```\n\nPress `Ctrl+C`\n\nto stop the loop.\n\n```\nemailai/\n├── main.go              # Entry point and CLI\n├── config/\n│   └── config.go        # Configuration management\n├── sync/\n│   └── sync.go          # IMAP sync engine\n├── store/\n│   └── store.go         # Local email storage\n├── ai/\n│   └── ai.go            # AI processing (OpenAI/Anthropic/Ollama)\n├── smtp/\n│   └── smtp.go          # Email sending\n├── config.example.json  # Example configuration\n└── README.md\n```\n\n| Option | Description | Default |\n|---|---|---|\n`imap.host` |\nIMAP server hostname | `imap.gmail.com` |\n`imap.port` |\nIMAP server port | `993` |\n`imap.username` |\nEmail address | - |\n`imap.password` |\nApp password | - |\n`imap.tls` |\nUse TLS encryption | `true` |\n`smtp.host` |\nSMTP server hostname | `smtp.gmail.com` |\n`smtp.port` |\nSMTP server port | `587` |\n`ai.enabled` |\nEnable AI features | `false` |\n`ai.provider` |\nAI provider (`openai` , `anthropic` , `ollama` ) |\n`openai` |\n`ai.model` |\nModel to use | `gpt-4` |\n`sync.interval` |\nSync interval in seconds | `300` |\n`sync.folders` |\nFolders to sync (empty = all) | `[]` |\n`sync.max_batch_size` |\nMax emails per sync batch | `100` |\n`sync.store_path` |\nLocal storage path | `./emails` |\n`sync.timeout_seconds` |\nMaximum time for one IMAP command | `120` |\n`sync.maildir_path` |\nLocal Maildir root managed by mbsync/isync | empty |\n`filters.exclude_newsletters` |\nExclude matching newsletter/marketing emails from local search and analyze results | `false` |\n`filters.exclude_from` |\nSender substrings to exclude when newsletter filtering is enabled | newsletter/no-reply/etc. |\n`filters.exclude_subject` |\nSubject substrings to exclude when newsletter filtering is enabled | newsletter/digest/etc. |\n`filters.exclude_body` |\nBody substrings to exclude when newsletter filtering is enabled | unsubscribe/etc. |\n`ocr.enabled` |\nRun local OCR on image attachments | `false` |\n`ocr.command` |\nOCR executable | `tesseract` |\n`ocr.languages` |\nTesseract language list | `eng` |\n`ocr.timeout_seconds` |\nMaximum OCR runtime per image | `60` |\n`ocr.max_bytes` |\nMaximum image size sent to OCR | `10485760` |\n\nWhen `ocr.enabled`\n\nis 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.\n\nNormal syncs store a per-folder IMAP UID watermark and fetch only newer messages. Use `-full-sync`\n\nto rescan every message, for example after enabling OCR or changing message parsing.\n\nSet `filters.exclude_newsletters`\n\nto `true`\n\nto keep obvious newsletters, promotions, and automated bulk mail out of `search`\n\nand `analyze`\n\nresults. Tune the `exclude_from`\n\n, `exclude_subject`\n\n, and `exclude_body`\n\nlists for your mailbox.\n\nTo use `mbsync`\n\n/`isync`\n\nfor mailbox synchronization, set `sync.maildir_path`\n\nto the Maildir root. When this is configured, the application reads local Maildir files and does not connect to IMAP. Run `mbsync`\n\nfirst, then run `./emailai -action sync`\n\nto import new messages and process OCR.\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n- Fork the repository\n- Create your feature branch (\n`git checkout -b feature/amazing-feature`\n\n) - Commit your changes (\n`git commit -m 'Add amazing feature'`\n\n) - Push to the branch (\n`git push origin feature/amazing-feature`\n\n) - Open a Pull Request\n\nThis project is licensed under the MIT License - see the [LICENSE](/peterretief/emailai/blob/main/LICENSE) file for details.\n\n- Never commit your\n`config.json`\n\nfile (it's in`.gitignore`\n\n) - Use App Passwords, not your regular email password\n- Keep your AI API keys secure\n- The\n`emails/`\n\ndirectory contains your synced emails - treat it as sensitive data\n\n[go-imap](https://github.com/emersion/go-imap)- IMAP library for Go[go-imap-idle](https://github.com/emersion/go-imap-idle)- IDLE extension[go-message](https://github.com/emersion/go-message)- Email message parsing\n\nIf you have any questions or issues, please open an issue on GitHub.", "url": "https://wpnews.pro/news/ai-powered-email-agent-that-syncs-your-emails-via-imap", "canonical_source": "https://github.com/peterretief/emailai/tree/main", "published_at": "2026-08-26 09:28:40+00:00", "updated_at": "2026-08-26 09:44:59.095520+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "artificial-intelligence"], "entities": ["EmailAI", "OpenAI", "Anthropic", "Ollama", "Gmail", "Outlook", "GitHub", "peterretief"], "alternates": {"html": "https://wpnews.pro/news/ai-powered-email-agent-that-syncs-your-emails-via-imap", "markdown": "https://wpnews.pro/news/ai-powered-email-agent-that-syncs-your-emails-via-imap.md", "text": "https://wpnews.pro/news/ai-powered-email-agent-that-syncs-your-emails-via-imap.txt", "jsonld": "https://wpnews.pro/news/ai-powered-email-agent-that-syncs-your-emails-via-imap.jsonld"}}