get_email_content
Extract detailed content from a specific email using its unique identifier, enabling efficient management and analysis of email data within the Email MCP Server.
Instructions
获取指定邮件的详细内容
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | 邮件唯一标识符 |
Implementation Reference
- index.js:875-956 (handler)The main handler function that executes the tool logic: connects to IMAP using createIMAPConnection, fetches the email by UID, parses it using simpleParser, formats the content (headers, text, HTML, attachments list), and returns it in MCP format.async getEmailContent(args) { const { uid } = args; return new Promise((resolve, reject) => { const imap = this.createIMAPConnection(); imap.once('ready', () => { imap.openBox('INBOX', true, (err, box) => { if (err) { imap.end(); return reject(err); } // 获取指定UID的邮件 const fetch = imap.fetch([uid], { bodies: '', struct: true }); fetch.on('message', (msg, seqno) => { msg.on('body', (stream, info) => { simpleParser(stream, (err, parsed) => { imap.end(); if (err) { return reject(err); } let content = `📧 邮件详情 (UID: ${uid})\n`; content += `────────────────────────────────\n`; content += `📅 日期: ${parsed.date || '未知'}\n`; content += `👤 发件人: ${parsed.from?.text || '未知'}\n`; content += `👥 收件人: ${parsed.to?.text || '未知'}\n`; if (parsed.cc) { content += `📋 抄送: ${parsed.cc.text}\n`; } content += `📝 主题: ${parsed.subject || '(无主题)'}\n`; content += `────────────────────────────────\n`; // 邮件内容 if (parsed.text) { content += `📄 文本内容:\n${parsed.text}\n`; } if (parsed.html && parsed.html !== parsed.text) { content += `🌐 HTML内容:\n${parsed.html}\n`; } // 附件信息 if (parsed.attachments && parsed.attachments.length > 0) { content += `📎 附件列表:\n`; parsed.attachments.forEach((att, index) => { content += ` ${index + 1}. ${att.filename || '未命名'} (${att.size || 0} bytes)\n`; }); } resolve({ content: [{ type: 'text', text: content }] }); }); }); }); fetch.once('error', (err) => { imap.end(); reject(err); }); }); }); imap.once('error', (err) => { reject(err); }); imap.connect(); }); }
- index.js:233-246 (registration)Tool registration entry in the tools array provided to this.server.setTools(), defining the tool name, description, and input schema.{ name: 'get_email_content', description: '获取指定邮件的详细内容', inputSchema: { type: 'object', properties: { uid: { type: 'string', description: '邮件唯一标识符' } }, required: ['uid'] } },
- index.js:236-245 (schema)Input schema for the get_email_content tool, defining the required 'uid' parameter as a string.inputSchema: { type: 'object', properties: { uid: { type: 'string', description: '邮件唯一标识符' } }, required: ['uid'] }
- index.js:350-351 (registration)Dispatch case in the CallToolRequestHandler switch statement that routes calls to the getEmailContent handler method.case 'get_email_content': return await this.getEmailContent(args);