Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

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
NameRequiredDescriptionDefault
uidYesEmail UID
mailboxNoMailbox name (default: current)

Implementation Reference

  • 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)
  • 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"],
    ),
  • 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"),
        )

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/Soundhannes/IMAP-MCP'

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