Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

save_draft

Save email drafts with recipient, subject, and body, automatically adding configured signatures for later editing or sending.

Instructions

Save email as draft (automatically includes user signature from config)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesRecipient addresses
subjectYesEmail subject
bodyYesEmail body (plain text)
ccNoCC addresses
bccNoBCC addresses
htmlBodyNoEmail body (HTML, optional)
draftsFolderNoDrafts folder name (default: Drafts)
includeSignatureNoInclude signature from config (default: true)

Implementation Reference

  • The `save_draft` method in the IMAP client handles the logic of creating and saving an email draft to the configured IMAP drafts folder.
    def save_draft(
        self,
        to: list[str],
        subject: str,
        body: str,
        cc: Optional[list[str]] = None,
        bcc: Optional[list[str]] = None,
        html_body: Optional[str] = None,
        drafts_folder: str = "Drafts",
        include_signature: bool = True,
    ) -> bool:
        """Save email as draft."""
        self._ensure_connected()
    
        from email.mime.text import MIMEText
        from email.mime.multipart import MIMEMultipart
    
        # Append signature if enabled
        final_body = body
        final_html = html_body
    
        if include_signature:
            text_sig = self.get_signature("text")
            if text_sig:
                final_body = body + text_sig
    
            if html_body:
                html_sig = self.get_signature("html")
                if html_sig:
                    final_html = html_body + html_sig
    
        # Set From header from config
        user_config = self.config.get("user", {})
        from_name = user_config.get("name", "")
        from_email = user_config.get("email", self.config.get("credentials", {}).get("username", ""))
    
        if final_html:
            msg = MIMEMultipart("alternative")
            msg.attach(MIMEText(final_body, "plain"))
            msg.attach(MIMEText(final_html, "html"))
        else:
            msg = MIMEText(final_body)
    
        msg["To"] = ", ".join(to)
        msg["Subject"] = subject
        if from_name and from_email:
            msg["From"] = f"{from_name} <{from_email}>"
        elif from_email:
            msg["From"] = from_email
        if cc:
            msg["Cc"] = ", ".join(cc)
        if bcc:
            msg["Bcc"] = ", ".join(bcc)
        msg["Date"] = email.utils.formatdate(localtime=True)
    
        self.client.append(
            drafts_folder,
            msg.as_bytes(),
            flags=[b"\\Draft"],
        )
        return True
  • The tool `save_draft` is registered and routed in the `server.py` main handler logic.
    elif name == "save_draft":
        return imap_client.save_draft(

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