get_email
Retrieve complete email messages by UID from IMAP mailboxes for reading and processing email content.
Instructions
Get complete email by UID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | Email UID | |
| mailbox | No | Mailbox name (default: current) |
Implementation Reference
- src/imap_mcp/imap_client.py:303-322 (handler)Implementation of `get_email` in `ImapClientWrapper`, which fetches complete email data (headers, body, attachments) by UID.
def get_email(self, uid: int, mailbox: Optional[str] = None) -> Email: """Get complete email by UID.""" self._ensure_connected() if mailbox: self.select_mailbox(mailbox) data = self.client.fetch([uid], ["ENVELOPE", "FLAGS", "RFC822.SIZE", "BODY[]"]) if uid not in data: raise ValueError(f"Email with UID {uid} not found") msg_data = data[uid] header = self._parse_email_header(uid, msg_data) # Parse body raw_body = msg_data.get(b"BODY[]", b"") msg = email.message_from_bytes(raw_body) body = self._extract_body(msg) attachments = self._extract_attachment_info(msg) return Email(header=header, body=body, attachments=attachments) - src/imap_mcp/server.py:113-121 (registration)Tool registration for `get_email` in `src/imap_mcp/server.py`.
make_tool( "get_email", "Get complete email by UID", { "uid": {"type": "number", "description": "Email UID"}, "mailbox": {"type": "string", "description": "Mailbox name (default: current)"}, }, ["uid"], ), - src/imap_mcp/server.py:510-514 (handler)Tool handler for `get_email` in `src/imap_mcp/server.py` that routes to `imap_client.get_email`.
elif name == "get_email": return imap_client.get_email( uid=args["uid"], mailbox=args.get("mailbox"), )