Skip to main content
Glama
railsware

Mailtrap Email Sending

by railsware

update-template

Modify existing email templates in Mailtrap Email Sending by updating subject lines, HTML content, plain text versions, names, or categories for transactional emails.

Instructions

Update an existing email template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_idYesID of the template to update
nameNoNew name for the template
subjectNoNew email subject line
htmlNoNew HTML content of the template
textNoNew plain text version of the template
categoryNoNew category for the template

Implementation Reference

  • Implementation of the updateTemplate handler function that performs the actual API call to update the email template via Mailtrap client, including validation and error handling.
    async function updateTemplate({ template_id, name, subject, html, text, category, }: UpdateTemplateRequest): Promise<{ content: any[]; isError?: boolean }> { try { if (!client) { throw new Error("MAILTRAP_API_TOKEN environment variable is required"); } // Validate that at least one update field is provided if ( name === undefined && subject === undefined && html === undefined && text === undefined && category === undefined ) { return { content: [ { type: "text", text: "Error: At least one update field (name, subject, html, text, or category) must be provided", }, ], isError: true, }; } // Validate that if both html and text are being updated, at least one has content if (html !== undefined && text !== undefined && !html && !text) { return { content: [ { type: "text", text: "Error: If updating both html and text, at least one must have content", }, ], isError: true, }; } const updateData: any = {}; if (name !== undefined) updateData.name = name; if (subject !== undefined) updateData.subject = subject; if (html !== undefined) updateData.body_html = html; if (text !== undefined) updateData.body_text = text; if (category !== undefined) updateData.category = category; const template = await client.templates.update(template_id, updateData); return { content: [ { type: "text", text: `Template "${template.name}" updated successfully!\nTemplate ID: ${template.id}\nTemplate UUID: ${template.uuid}`, }, ], }; } catch (error) { console.error("Error updating template:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to update template: ${errorMessage}`, }, ], isError: true, }; } }
  • JSON Schema defining the input structure for the 'update-template' tool, specifying properties like template_id (required), name, subject, html, text, category.
    const updateTemplateSchema = { type: "object", properties: { template_id: { type: "number", description: "ID of the template to update", }, name: { type: "string", description: "New name for the template", }, subject: { type: "string", description: "New email subject line", }, html: { type: "string", description: "New HTML content of the template", }, text: { type: "string", description: "New plain text version of the template", }, category: { type: "string", description: "New category for the template", }, }, required: ["template_id"], additionalProperties: false, };
  • src/server.ts:64-72 (registration)
    Registration of the 'update-template' tool in the tools array of the MCP server, specifying name, description, inputSchema, handler, and annotations.
    { name: "update-template", description: "Update an existing email template", inputSchema: updateTemplateSchema, handler: updateTemplate, annotations: { destructiveHint: true, }, },

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/railsware/mailtrap-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server