add-email-template
Create reusable email templates with customizable subject and body content for automated email sending through SMTP MCP Server.
Instructions
Add a new email template
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the template | |
| subject | Yes | Email subject template | |
| body | Yes | Email body template | |
| isDefault | No | Whether this template should be the default |
Implementation Reference
- src/requestHandler.ts:427-469 (handler)The core handler function that implements the add-email-template tool logic. It retrieves existing templates, creates a new EmailTemplate with a generated UUID, handles the isDefault flag by unsetting it on other default templates, saves the new template, and returns success with the new template details or error information.
async function handleAddEmailTemplate(parameters: any) { try { // Get existing templates const templates = await getEmailTemplates(); // Create a new template const newTemplate: EmailTemplate = { id: generateUUID(), name: parameters.name, subject: parameters.subject, body: parameters.body, isDefault: parameters.isDefault ?? false }; // If this is set as default, we'll need to update other templates if (newTemplate.isDefault) { templates.forEach(template => { if (template.isDefault) { template.isDefault = false; saveEmailTemplate(template).catch(err => { logToFile('Error updating template:'); logToFile(err instanceof Error ? err.message : 'Unknown error'); }); } }); } // Save the new template await saveEmailTemplate(newTemplate); return { success: true, template: newTemplate }; } catch (error) { logToFile('Error in handleAddEmailTemplate:'); logToFile(error instanceof Error ? error.message : 'Unknown error'); return { success: false, message: error instanceof Error ? error.message : 'Unknown error' }; } } - src/tools.ts:295-320 (schema)Tool definition including name, description, and input schema specifying required parameters: name, subject, body; optional: isDefault.
"add-email-template": { name: "add-email-template", description: "Add a new email template", inputSchema: { type: "object", properties: { 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: ["name", "subject", "body"] } }, - src/requestHandler.ts:90-91 (registration)The switch case in the CallToolRequestSchema handler that routes 'add-email-template' tool calls to the handleAddEmailTemplate function.
case "add-email-template": return await handleAddEmailTemplate(toolParams);