search_sent_emails
Find sent emails in Outlook using search keywords to retrieve specific messages from your sent items folder.
Instructions
Search sent emails
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search keywords | |
| count | No | Number of results to return |
Implementation Reference
- src/outlook-manager.ts:374-379 (handler)Core handler function for search_sent_emails tool. Fetches a batch of recent sent emails, applies semantic search using EmailSummarizer, and returns top matching results.async searchSentEmails(query: string, count: number = 10): Promise<EmailMessage[]> { const emails = await this.getSentEmails(Math.min(count * 2, 50)); const { EmailSummarizer } = await import('./email-summarizer.js'); const searchResults = EmailSummarizer.searchEmails(emails, query); return searchResults.slice(0, count); }
- src/email-summarizer.ts:42-62 (helper)Key helper method implementing case-insensitive full-text search across email subject, sender, and body (stripping HTML).static searchEmails(emails: EmailMessage[], searchTerm: string): EmailMessage[] { if (!searchTerm.trim()) { return emails; } const normalizedSearchTerm = searchTerm.toLowerCase(); return emails.filter(email => { // Search in subject const subjectMatch = email.subject.toLowerCase().includes(normalizedSearchTerm); // Search in sender const senderMatch = email.sender.toLowerCase().includes(normalizedSearchTerm); // Search in body content (remove HTML tags before searching) const cleanBody = email.body.replace(/<[^>]*>/g, '').toLowerCase(); const bodyMatch = cleanBody.includes(normalizedSearchTerm); return subjectMatch || senderMatch || bodyMatch; }); }
- src/index.ts:587-605 (registration)MCP server dispatch handler for search_sent_emails tool calls, validating inputs and formatting response.case 'search_sent_emails': { const query = (args as any)?.query; const count = (args as any)?.count || 10; if (!query) { throw new Error('Search query is required'); } const emails = await outlookManager.searchSentEmails(query, count); return { content: [ { type: 'text', text: `š **Search Results: "${query}"**\nTotal: ${emails.length} items\nUnread: ${emails.filter(e => !e.isRead).length} items\n\nš **Search Results List:**\n` + emails.map((email, index) => `${index + 1}. ${email.isRead ? 'ā ' : 'š©'} **${email.subject}**\n From: ${email.sender}\n Time: ${email.receivedTime}\n EntryID: ${email.id}\n StoreID: ${email.storeId || 'N/A'}\n Search Context: ${email.body?.includes(query) ? 'Match in content' : 'Match in subject'}: ${email.subject}\n Preview: ${email.body?.substring(0, 100)}...\n` ).join('\n') }, ], }; }
- src/index.ts:151-169 (schema)Tool registration including name, description, and input schema (query: string required, count: number optional default 10).{ name: "search_sent_emails", description: "Search sent emails", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search keywords" }, count: { type: "number", description: "Number of results to return", default: 10 } }, required: ["query"] } },
- src/outlook-manager.ts:220-222 (helper)Helper method to retrieve recent sent emails from Outlook Sent Items folder using PowerShell automation.async getSentEmails(count: number = 10): Promise<EmailMessage[]> { return this.getEmailsFromFolder(5, count, "[SentOn]"); // 5 = Sent Items }