create-template
Create email templates for transactional emails with customizable HTML, text content, and categories to streamline email communication workflows.
Instructions
Create a new email template
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the template | |
| subject | Yes | Email subject line | |
| html | No | HTML content of the template (optional) | |
| text | No | Plain text version of the template (optional) | |
| category | No | Template category (optional, defaults to 'General') |
Implementation Reference
- The handler function for the 'create-template' tool. It creates a new email template using the Mailtrap API client, validates inputs, handles errors, and returns success or error messages.import { CreateTemplateRequest } from "../../types/mailtrap"; import { client } from "../../client"; async function createTemplate({ name, subject, html, text, category, }: CreateTemplateRequest): Promise<{ content: any[]; isError?: boolean }> { try { if (!client) { throw new Error("MAILTRAP_API_TOKEN environment variable is required"); } // Validate that at least one of html or text is provided if (!html && !text) { return { content: [ { type: "text", text: "Failed to create template: At least one of 'html' or 'text' content must be provided.", }, ], isError: true, }; } const createParams: any = { name, subject, category: category || "General", }; if (html) { createParams.body_html = html; } if (text) { createParams.body_text = text; } const template = await client.templates.create(createParams); return { content: [ { type: "text", text: `Template "${name}" created successfully!\nTemplate ID: ${template.id}\nTemplate UUID: ${template.uuid}`, }, ], }; } catch (error) { console.error("Error creating template:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to create template: ${errorMessage}`, }, ], isError: true, }; } } export default createTemplate;
- The input schema for the 'create-template' tool, defining properties like name, subject, html, text, category with required fields.const createTemplateSchema = { type: "object", properties: { name: { type: "string", description: "Name of the template", }, subject: { type: "string", description: "Email subject line", }, html: { type: "string", description: "HTML content of the template (optional)", }, text: { type: "string", description: "Plain text version of the template (optional)", }, category: { type: "string", description: "Template category (optional, defaults to 'General')", }, }, required: ["name", "subject"], additionalProperties: false, }; export default createTemplateSchema;
- src/server.ts:46-54 (registration)Registration of the 'create-template' tool in the tools array, linking schema and handler.{ name: "create-template", description: "Create a new email template", inputSchema: createTemplateSchema, handler: createTemplate, annotations: { destructiveHint: true, }, },