# Templates

Create and manage reusable email templates with dynamic content.

## Get all Email Templates

> Get all email templates existing in your account

```json
{"openapi":"3.1.0","info":{"title":"Templates","version":"2.0.0"},"tags":[{"name":"templates","description":"Create and manage reusable email templates with dynamic content."}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"API token in Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Bearer token authentication"}},"schemas":{"EmailTemplateResponse":{"title":"EmailTemplateResponse","type":"object","properties":{"id":{"type":"integer"},"uuid":{"type":"string","format":"uuid"},"name":{"type":"string","maxLength":255},"category":{"type":"string","maxLength":255},"subject":{"type":"string","maxLength":255},"body_text":{"type":"string","maxLength":10000000},"body_html":{"type":"string","maxLength":10000000},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"ErrorResponse":{"type":"object","properties":{"success":{"type":"boolean"},"errors":{"type":"array","items":{"type":"string"}}}}},"responses":{"Unauthorized":{"description":"Unauthorized. Check your API credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"Forbidden. Verify domain or check permissions.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/api/accounts/{account_id}/email_templates":{"get":{"description":"Get all email templates existing in your account","operationId":"emailTemplates","summary":"Get all Email Templates","tags":["templates"],"responses":{"200":{"description":"OK.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/EmailTemplateResponse"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}}}}
```

## Create Email Template

> Create a new email template

```json
{"openapi":"3.1.0","info":{"title":"Templates","version":"2.0.0"},"tags":[{"name":"templates","description":"Create and manage reusable email templates with dynamic content."}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"API token in Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Bearer token authentication"}},"schemas":{"EmailTemplateRequest":{"title":"EmailTemplateRequest","type":"object","required":["email_template"],"properties":{"email_template":{"type":"object","required":["name","subject","category"],"properties":{"name":{"type":"string","maxLength":255},"category":{"type":"string","maxLength":255},"subject":{"type":"string","maxLength":255},"body_text":{"type":"string","maxLength":10000000},"body_html":{"type":"string","maxLength":10000000}}}}},"EmailTemplateResponse":{"title":"EmailTemplateResponse","type":"object","properties":{"id":{"type":"integer"},"uuid":{"type":"string","format":"uuid"},"name":{"type":"string","maxLength":255},"category":{"type":"string","maxLength":255},"subject":{"type":"string","maxLength":255},"body_text":{"type":"string","maxLength":10000000},"body_html":{"type":"string","maxLength":10000000},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"ErrorResponse":{"type":"object","properties":{"success":{"type":"boolean"},"errors":{"type":"array","items":{"type":"string"}}}},"UnprocessableEntity":{"type":"object","properties":{"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}},"responses":{"Unauthorized":{"description":"Unauthorized. Check your API credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"Forbidden. Verify domain or check permissions.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"UnprocessableEntity":{"description":"Validation errors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnprocessableEntity"}}}}}},"paths":{"/api/accounts/{account_id}/email_templates":{"post":{"description":"Create a new email template","operationId":"createEmailTemplate","summary":"Create Email Template","tags":["templates"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailTemplateRequest"}}}},"responses":{"201":{"description":"Email template created successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailTemplateResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"422":{"$ref":"#/components/responses/UnprocessableEntity"}}}}}}
```

## Get Email Template

> Get an email template by ID

```json
{"openapi":"3.1.0","info":{"title":"Templates","version":"2.0.0"},"tags":[{"name":"templates","description":"Create and manage reusable email templates with dynamic content."}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"API token in Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Bearer token authentication"}},"schemas":{"EmailTemplateResponse":{"title":"EmailTemplateResponse","type":"object","properties":{"id":{"type":"integer"},"uuid":{"type":"string","format":"uuid"},"name":{"type":"string","maxLength":255},"category":{"type":"string","maxLength":255},"subject":{"type":"string","maxLength":255},"body_text":{"type":"string","maxLength":10000000},"body_html":{"type":"string","maxLength":10000000},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"ErrorResponse":{"type":"object","properties":{"success":{"type":"boolean"},"errors":{"type":"array","items":{"type":"string"}}}}},"responses":{"Unauthorized":{"description":"Unauthorized. Check your API credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"Forbidden. Verify domain or check permissions.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFound":{"description":"Resource not found","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}},"paths":{"/api/accounts/{account_id}/email_templates/{email_template_id}":{"get":{"description":"Get an email template by ID","operationId":"getEmailTemplate","summary":"Get Email Template","tags":["templates"],"responses":{"200":{"description":"Returns attributes of the email template.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailTemplateResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}
```

## Delete Email Template

> Delete an email template

```json
{"openapi":"3.1.0","info":{"title":"Templates","version":"2.0.0"},"tags":[{"name":"templates","description":"Create and manage reusable email templates with dynamic content."}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"API token in Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Bearer token authentication"}},"responses":{"Unauthorized":{"description":"Unauthorized. Check your API credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"Forbidden. Verify domain or check permissions.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFound":{"description":"Resource not found","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}},"schemas":{"ErrorResponse":{"type":"object","properties":{"success":{"type":"boolean"},"errors":{"type":"array","items":{"type":"string"}}}}}},"paths":{"/api/accounts/{account_id}/email_templates/{email_template_id}":{"delete":{"description":"Delete an email template","operationId":"deleteEmailTemplate","summary":"Delete Email Template","tags":["templates"],"responses":{"204":{"description":"No Content"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}
```

## Update Email Template

> Update an email template

```json
{"openapi":"3.1.0","info":{"title":"Templates","version":"2.0.0"},"tags":[{"name":"templates","description":"Create and manage reusable email templates with dynamic content."}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"API token in Api-Token header","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Bearer token authentication"}},"schemas":{"EmailTemplateRequest":{"title":"EmailTemplateRequest","type":"object","required":["email_template"],"properties":{"email_template":{"type":"object","required":["name","subject","category"],"properties":{"name":{"type":"string","maxLength":255},"category":{"type":"string","maxLength":255},"subject":{"type":"string","maxLength":255},"body_text":{"type":"string","maxLength":10000000},"body_html":{"type":"string","maxLength":10000000}}}}},"EmailTemplateResponse":{"title":"EmailTemplateResponse","type":"object","properties":{"id":{"type":"integer"},"uuid":{"type":"string","format":"uuid"},"name":{"type":"string","maxLength":255},"category":{"type":"string","maxLength":255},"subject":{"type":"string","maxLength":255},"body_text":{"type":"string","maxLength":10000000},"body_html":{"type":"string","maxLength":10000000},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"ErrorResponse":{"type":"object","properties":{"success":{"type":"boolean"},"errors":{"type":"array","items":{"type":"string"}}}},"UnprocessableEntity":{"type":"object","properties":{"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}},"responses":{"Unauthorized":{"description":"Unauthorized. Check your API credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"Forbidden. Verify domain or check permissions.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFound":{"description":"Resource not found","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}},"UnprocessableEntity":{"description":"Validation errors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnprocessableEntity"}}}}}},"paths":{"/api/accounts/{account_id}/email_templates/{email_template_id}":{"patch":{"description":"Update an email template","operationId":"updateEmailTemplate","summary":"Update Email Template","tags":["templates"],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailTemplateRequest"}}}},"responses":{"200":{"description":"Email template updated successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmailTemplateResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"422":{"$ref":"#/components/responses/UnprocessableEntity"}}}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mailtrap.io/developers/templates/templates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
