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
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | Recipient addresses | |
| subject | Yes | Email subject | |
| body | Yes | Email body (plain text) | |
| cc | No | CC addresses | |
| bcc | No | BCC addresses | |
| htmlBody | No | Email body (HTML, optional) | |
| draftsFolder | No | Drafts folder name (default: Drafts) | |
| includeSignature | No | Include signature from config (default: true) |
Implementation Reference
- src/imap_mcp/imap_client.py:696-756 (handler)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 - src/imap_mcp/server.py:626-627 (registration)The tool `save_draft` is registered and routed in the `server.py` main handler logic.
elif name == "save_draft": return imap_client.save_draft(