get_email_body
Retrieve email body content from IMAP mailboxes in text or HTML format using email UID to access message content for reading or processing.
Instructions
Get email body content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | Email UID | |
| mailbox | No | Mailbox name (default: current) | |
| format | No | Body format (default: text) |
Implementation Reference
- src/imap_mcp/imap_client.py:336-354 (handler)The core logic for fetching and extracting the email body from an IMAP server.
def get_email_body( self, uid: int, mailbox: Optional[str] = None, format: str = "text" ) -> str: """Get email body content.""" self._ensure_connected() if mailbox: self.select_mailbox(mailbox) data = self.client.fetch([uid], ["BODY[]"]) if uid not in data: raise ValueError(f"Email with UID {uid} not found") raw_body = data[uid].get(b"BODY[]", b"") msg = email.message_from_bytes(raw_body) body = self._extract_body(msg) if format == "html" and body.html: return body.html return body.text or "" - src/imap_mcp/server.py:520-525 (registration)The MCP tool registration handler that calls the IMAP client's get_email_body method.
elif name == "get_email_body": return imap_client.get_email_body( uid=args["uid"], mailbox=args.get("mailbox"), format=args.get("format", "text"), )