Skip to main content
Glama

get_sent_emails

Retrieve a list of sent emails from Microsoft Outlook via the Outlook MCP Server. Specify the number of emails to access for efficient email management and monitoring.

Instructions

Get sent emails list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of sent emails to retrieve

Implementation Reference

  • src/index.ts:170-183 (registration)
    Registration of the get_sent_emails tool in the tools list, including name, description, and input schema.
    { name: "get_sent_emails", description: "Get sent emails list", inputSchema: { type: "object", properties: { count: { type: "number", description: "Number of sent emails to retrieve", default: 10 } } } },
  • MCP CallToolRequest handler for get_sent_emails: extracts count parameter, calls outlookManager.getSentEmails, formats and returns list of sent emails.
    case 'get_sent_emails': { const count = (args as any)?.count || 10; const emails = await outlookManager.getSentEmails(count); return { content: [ { type: 'text', text: `📊 **Email Overview**\nTotal: ${emails.length} emails\nUnread: ${emails.filter(e => !e.isRead).length} emails\n\n📋 **Email 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 Preview: ${email.body?.substring(0, 100)}...\n` ).join('\n') }, ], }; }
  • getSentEmails method: wrapper that calls shared getEmailsFromFolder for Sent Items folder (ID 5), sorting by SentOn.
    async getSentEmails(count: number = 10): Promise<EmailMessage[]> { return this.getEmailsFromFolder(5, count, "[SentOn]"); // 5 = Sent Items }
  • Core implementation: getEmailsFromFolder executes PowerShell script to interact with Outlook COM API, retrieves emails from specified folder (Sent Items for folderType=5), parses JSON output into EmailMessage objects.
    private async getEmailsFromFolder(folderType: number, count: number = 10, sortBy: string = "[ReceivedTime]"): Promise<EmailMessage[]> { const script = ` try { Add-Type -AssemblyName "Microsoft.Office.Interop.Outlook" -ErrorAction Stop $outlook = New-Object -ComObject Outlook.Application -ErrorAction Stop $namespace = $outlook.GetNamespace("MAPI") $folder = $namespace.GetDefaultFolder(${folderType}) if ($folder.Items.Count -eq 0) { Write-Output "[]" exit 0 } $items = $folder.Items $items.Sort("${sortBy}", $true) $emails = @() $counter = 0 foreach ($item in $items) { if ($counter -ge ${count}) { break } try { $subject = if ($item.Subject) { $item.Subject.ToString() -replace '[\\x00-\\x1F\\x7F]', '' } else { "No Subject" } $sender = if ($item.SenderEmailAddress) { $item.SenderEmailAddress.ToString() -replace '[\\x00-\\x1F\\x7F]', '' } else { "Unknown" } $body = if ($item.Body) { $bodyStr = $item.Body.ToString() -replace '[\\x00-\\x1F\\x7F]', '' if ($bodyStr.Length -gt 150) { $bodyStr.Substring(0, 150) + "..." } else { $bodyStr } } else { "" } $timeStamp = if ($item.SentOn -and ${folderType} -eq 5) { $item.SentOn.ToString("yyyy-MM-dd HH:mm:ss") } elseif ($item.ReceivedTime) { $item.ReceivedTime.ToString("yyyy-MM-dd HH:mm:ss") } else { (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") } $emails += [PSCustomObject]@{ Id = if ($item.EntryID) { $item.EntryID.ToString() } else { "no-id-$counter" } StoreID = if ($item.Session -and $item.Session.DefaultStore -and $item.Session.DefaultStore.StoreID) { $item.Session.DefaultStore.StoreID.ToString() } elseif ($item.Parent -and $item.Parent.StoreID) { $item.Parent.StoreID.ToString() } else { try { $namespace.DefaultStore.StoreID.ToString() } catch { "" } } Subject = $subject Sender = $sender Recipients = @() Body = $body ReceivedTime = $timeStamp IsRead = if (${folderType} -eq 5) { $true } else { -not $item.UnRead } HasAttachments = $item.Attachments.Count -gt 0 } $counter++ } catch { $counter++; continue } } if ($emails.Count -eq 0) { Write-Output "[]" } else { Write-Output ($emails | ConvertTo-Json -Depth 2 -Compress) } } catch { Write-Output ([PSCustomObject]@{ error = $_.Exception.Message; type = "OutlookConnectionError" } | ConvertTo-Json -Compress) } `; try { const result = await this.executePowerShell(script); if (!result || result.trim() === '') return []; const cleanResult = result.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, '').trim(); const parsed = JSON.parse(cleanResult); if (parsed.error) throw new Error(`Outlook Error: ${parsed.error}`); const emailArray = Array.isArray(parsed) ? parsed : [parsed]; return emailArray.map((item: any) => ({ id: this.cleanText(item.Id || ''), storeId: this.cleanText(item.StoreID || ''), subject: this.cleanText(item.Subject || 'No Subject'), sender: this.cleanText(item.Sender || 'Unknown'), recipients: [], body: this.cleanText(item.Body || ''), receivedTime: new Date(item.ReceivedTime), isRead: Boolean(item.IsRead), hasAttachments: Boolean(item.HasAttachments) })); } catch (error) { console.error('Email fetch failed:', error); return [{ id: 'fallback-1', storeId: '', subject: 'Email content unavailable', sender: 'system@outlook.com', recipients: [], body: 'Unable to retrieve email content.', receivedTime: new Date(), isRead: true, hasAttachments: false }]; } }
  • EmailMessage TypeScript interface defining the structure of email objects returned by getSentEmails.
    export interface EmailMessage { id: string; storeId?: string; subject: string; sender: string; recipients: string[]; body: string; receivedTime: Date; isRead: boolean; hasAttachments: boolean; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cqyefeng119/windows-outlook-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server