Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

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

Implementation Reference

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

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