Skip to main content
Glama

deleteEmail

Remove unwanted emails from your inbox using UID and folder parameters to manage email clutter effectively.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYes
folderNoINBOX

Implementation Reference

  • Handler for the 'deleteEmail' tool: validates input parameters using Zod, calls mailService.deleteMail to perform the deletion via IMAP, and returns a formatted text response indicating success or failure.
    this.server.tool( "deleteEmail", { uid: z.number(), folder: z.string().default('INBOX') }, async ({ uid, folder }) => { try { const numericUid = Number(uid); const success = await this.mailService.deleteMail(numericUid, folder); if (success) { return { content: [ { type: "text", text: `邮件(UID: ${numericUid})已从${folder}文件夹中删除` } ] }; } else { return { content: [ { type: "text", text: `删除邮件(UID: ${numericUid})失败` } ] }; } } catch (error) { return { content: [ { type: "text", text: `删除邮件时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
  • Input schema for deleteEmail tool using Zod: requires uid (number) and optional folder (string, defaults to 'INBOX').
    { uid: z.number(), folder: z.string().default('INBOX') },
  • Registration of the 'deleteEmail' MCP tool on the server, specifying the name, input schema, and handler function.
    this.server.tool( "deleteEmail", { uid: z.number(), folder: z.string().default('INBOX') }, async ({ uid, folder }) => { try { const numericUid = Number(uid); const success = await this.mailService.deleteMail(numericUid, folder); if (success) { return { content: [ { type: "text", text: `邮件(UID: ${numericUid})已从${folder}文件夹中删除` } ] }; } else { return { content: [ { type: "text", text: `删除邮件(UID: ${numericUid})失败` } ] }; } } catch (error) { return { content: [ { type: "text", text: `删除邮件时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
  • MailService.deleteMail helper method: connects to IMAP, adds \Deleted flag to the specified UID in the folder, expunges to permanently delete, returns boolean success.
    async deleteMail(uid: number | string, folder: string = 'INBOX'): Promise<boolean> { await this.connectImap(); // 确保 uid 为数字类型 const numericUid = typeof uid === 'string' ? parseInt(uid, 10) : uid; return new Promise((resolve, reject) => { this.imapClient.openBox(folder, false, (err) => { if (err) { reject(err); return; } this.imapClient.addFlags(numericUid, '\\Deleted', (err) => { if (err) { reject(err); return; } this.imapClient.expunge((err) => { if (err) { reject(err); return; } resolve(true); }); }); }); }); }

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/shuakami/mcp-mail'

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