Skip to main content
Glama

get-email-content

Retrieve full email content by ID to access complete message details, attachments, and conversation history for email management and reference.

Instructions

Get the full content of a specific email by its ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
email_idYesThe ID of the email to retrieve

Implementation Reference

  • Dispatch handler in call_tool for 'get-email-content': validates input, calls get_email_content_async, formats and returns the full email content with timeout handling.
    elif name == "get-email-content": email_id = arguments.get("email_id") if not email_id: return [types.TextContent( type="text", text="Email ID is required." )] try: async with asyncio.timeout(SEARCH_TIMEOUT): email_content = await get_email_content_async(mail, email_id) result_text = ( f"From: {email_content['from']}\n" f"To: {email_content['to']}\n" f"Date: {email_content['date']}\n" f"Subject: {email_content['subject']}\n" f"\nContent:\n{email_content['content']}" ) return [types.TextContent( type="text", text=result_text )] except asyncio.TimeoutError: return [types.TextContent( type="text", text="Operation timed out while fetching email content." )]
  • Specific handler function that fetches the email message data via IMAP and delegates to format_email_content for parsing.
    async def get_email_content_async(mail: imaplib.IMAP4_SSL, email_id: str) -> dict: """Asynchronously get full content of a specific email.""" loop = asyncio.get_event_loop() try: _, msg_data = await loop.run_in_executor(None, lambda: mail.fetch(email_id, '(RFC822)')) return format_email_content(msg_data) except Exception as e: raise Exception(f"Error fetching email content: {str(e)}")
  • Helper function to parse raw email bytes into structured dict: extracts headers and prefers text/plain body, falls back to HTML or single part.
    def format_email_content(msg_data: tuple) -> dict: """Format an email message into a dict with full content.""" email_body = email.message_from_bytes(msg_data[0][1]) # Extract body content body = "" if email_body.is_multipart(): # Handle multipart messages for part in email_body.walk(): if part.get_content_type() == "text/plain": body = part.get_payload(decode=True).decode() break elif part.get_content_type() == "text/html": # If no plain text found, use HTML content if not body: body = part.get_payload(decode=True).decode() else: # Handle non-multipart messages body = email_body.get_payload(decode=True).decode() return { "from": email_body.get("From", "Unknown"), "to": email_body.get("To", "Unknown"), "date": email_body.get("Date", "Unknown"), "subject": email_body.get("Subject", "No Subject"), "content": body }
  • Tool registration within handle_list_tools(): defines name, description, and JSON schema for input (email_id required).
    types.Tool( name="get-email-content", description="Get the full content of a specific email by its ID", inputSchema={ "type": "object", "properties": { "email_id": { "type": "string", "description": "The ID of the email to retrieve", }, }, "required": ["email_id"], }, ),

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/meyannis/mcpemail'

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