update-email-template
Modify existing email templates in the SMTP MCP Server by updating subject, body, name, or default status to maintain consistent communication.
Instructions
Update an existing email template
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID of the template to update | |
| name | No | Name of the template | |
| subject | No | Email subject template | |
| body | No | Email body template | |
| isDefault | No | Whether this template should be the default |
Implementation Reference
- src/requestHandler.ts:471-529 (handler)The core handler function that implements the update-email-template tool logic. It retrieves email templates, finds the one by ID, applies updates to name, subject, body, and isDefault flag (handling default conflicts), then saves the updated template.
/** * Handle update-email-template tool call */ async function handleUpdateEmailTemplate(parameters: any) { try { // Get existing templates const templates = await getEmailTemplates(); // Find the template to update const template = templates.find(t => t.id === parameters.id); if (!template) { return { success: false, message: `Email template with ID ${parameters.id} not found` }; } // Update the template const updatedTemplate = { ...template }; if (parameters.name !== undefined) updatedTemplate.name = parameters.name; if (parameters.subject !== undefined) updatedTemplate.subject = parameters.subject; if (parameters.body !== undefined) updatedTemplate.body = parameters.body; // Handle default flag if (parameters.isDefault !== undefined && parameters.isDefault !== template.isDefault) { updatedTemplate.isDefault = parameters.isDefault; // If setting as default, update other templates if (updatedTemplate.isDefault) { templates.forEach(t => { if (t.id !== parameters.id && t.isDefault) { t.isDefault = false; saveEmailTemplate(t).catch(err => { logToFile('Error updating template:'); logToFile(err instanceof Error ? err.message : 'Unknown error'); }); } }); } } // Save the updated template await saveEmailTemplate(updatedTemplate); return { success: true, template: updatedTemplate }; } catch (error) { logToFile('Error in handleUpdateEmailTemplate:'); logToFile(error instanceof Error ? error.message : 'Unknown error'); return { success: false, message: error instanceof Error ? error.message : 'Unknown error' }; } } - src/tools.ts:322-351 (schema)Defines the tool's metadata (name, description) and input schema for validation, specifying required 'id' and optional fields for updating the template.
"update-email-template": { name: "update-email-template", description: "Update an existing email template", inputSchema: { type: "object", properties: { id: { type: "string", description: "ID of the template to update" }, name: { type: "string", description: "Name of the template" }, subject: { type: "string", description: "Email subject template" }, body: { type: "string", description: "Email body template" }, isDefault: { type: "boolean", description: "Whether this template should be the default" } }, required: ["id"] } }, - src/requestHandler.ts:93-94 (registration)Registers the tool handler dispatch within the MCP tool call request handler switch statement.
case "update-email-template": return await handleUpdateEmailTemplate(toolParams);