delete_email
Move an email to the trash using its ID to remove it from your inbox.
Instructions
Delete an email (move to trash)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes | ID of the email to delete |
Implementation Reference
- src/index.ts:648-661 (registration)Tool registration: defines the 'delete_email' MCP tool name, description, and input schema (requires emailId).
{ name: 'delete_email', description: 'Delete an email (move to trash)', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to delete', }, }, required: ['emailId'], }, }, - src/index.ts:1441-1456 (handler)Handler: the switch-case branch that extracts emailId, validates it, calls client.deleteEmail(), and returns success message.
case 'delete_email': { const { emailId } = args as any; if (!emailId) { throw new McpError(ErrorCode.InvalidParams, 'emailId is required'); } const client = initializeClient(); await client.deleteEmail(emailId); return { content: [ { type: 'text', text: 'Email deleted successfully (moved to trash)', }, ], }; } - src/jmap-client.ts:802-836 (helper)Helper: JmapClient.deleteEmail() — the actual JMAP API call. Finds the Trash mailbox and uses Email/set to move the email there (by setting its mailboxIds to the trash mailbox).
async deleteEmail(emailId: string): Promise<void> { const session = await this.getSession(); // Find the trash mailbox const mailboxes = await this.getMailboxes(); const trashMailbox = this.findMailboxByRoleOrName(mailboxes, 'trash', 'trash'); if (!trashMailbox) { throw new Error('Could not find Trash mailbox'); } const trashMailboxIds: Record<string, boolean> = {}; trashMailboxIds[trashMailbox.id] = true; const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: { [emailId]: { mailboxIds: trashMailboxIds } } }, 'moveToTrash'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && result.notUpdated[emailId]) { throw new Error('Failed to delete email.'); } }