Skip to main content
Glama
railsware

Mailtrap Email Sending

by railsware

create-template

Create reusable email templates with HTML and plain text versions for transactional emails in Mailtrap Email Sending.

Instructions

Create a new email template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the template
subjectYesEmail subject line
htmlNoHTML content of the template (optional)
textNoPlain text version of the template (optional)
categoryNoTemplate category (optional, defaults to 'General')

Implementation Reference

  • The handler function that implements the logic for creating a new email template using the Mailtrap API client. It validates inputs, calls the API, and returns success or error content.
    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, }; } }
  • JSON schema defining the input parameters for the create-template tool, including name, subject, optional html/text content, and category.
    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, };
  • src/server.ts:46-54 (registration)
    Tool registration in the server's tools array, linking the name, description, schema, handler, and annotations.
    { name: "create-template", description: "Create a new email template", inputSchema: createTemplateSchema, handler: createTemplate, 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