{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/mailgun/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Using Templates","siteUrl":"https://documentation.mailgun.com","llmstxt":{"title":"Mailgun Documentation","description":"LLMS.txt containing a map of all the documentation files for Mailgun.","sections":[{"title":"Mailgun Send Documentation","description":"All of the Mailgun Send documentation.","includeFiles":["docs/mailgun/**/*.md"],"excludeFiles":["docs/mailgun/index.md"]},{"title":"Mailgun Send OAS","description":"All of the Mailgun Send API specifications.","includeFiles":["docs/mailgun/**/mailgun.yaml"]},{"title":"Mailgun Optimize Documentation","description":"All of the Mailgun Optimize documentation.","includeFiles":["docs/inboxready/**/*.md"],"excludeFiles":["docs/inboxready/index.md"]},{"title":"Mailgun Optimize OAS","description":"All of the Mailgun Optimize API specifications","includeFiles":["docs/inboxready/**/inboxready.yaml"]},{"title":"Mailgun Validate Documentation","description":"All of the Mailgun Validate documentation.","includeFiles":["docs/validate/**/*.md"],"excludeFiles":["docs/validate/index.md"]},{"title":"Mailgun Validate OAS","description":"All of the Mailgun Validate API specifications.","includeFiles":["docs/validate/**/*.yaml"]},{"title":"Mailgun Inspect Documentation","description":"All of the Mailgun Inspect documentation.","includeFiles":["docs/inspect/**/overview.md"]},{"title":"Mailgun Inspect OAS","description":"All of the Mailgun Inspect API specifications.","includeFiles":["docs/inspect/**/*.yaml"]}]},"description":"How to manage Mailgun templates"},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"templates","__idx":0},"children":["Templates"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Mailgun allows you to store predefined email content via Templates allowing the ability to send messages by simply referencing the template name. Using Mailgun to create, manage, and use your email templates can eliminate costly overhead from your tech stack and centralize your email workflow."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":""},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Mailgun caps usage of account-level templates to 100 templates and 40 versions per template. Domain-scoped templates have same limit set on a per sending domain basis."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Templates can either be created under a specific sending domain or for greater flexibility, created at the account level."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"domain-level-templates","__idx":1},"children":["Domain Level Templates"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Templates stored and scoped per sending domain. The template must be associated with your domain when sending email."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"account-level-templates","__idx":2},"children":["Account Level Templates"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Provides the greatest flexibility allowing sending account level templates across any sending domain under account as well as on behalf of subaccounts. Domain scoped templates can be copied to account-level and account-level templates can be copied to subaccounts for direct subaccount template management and sending."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"template-id","__idx":3},"children":["Template ID"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In place of using template name for sending email users can, alternatively, use the unique template ID associated with your templates. This dev-friendly option also allows account-level templates to be more easily sent across domains and even subaccounts via the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["X-On-Behalf-Of"]}," ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://documentation.mailgun.com/docs/mailgun/user-manual/subaccounts/subaccounts-api-requests"},"children":["header"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"regions","__idx":4},"children":["Regions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Templates are isolated to a region, meaning you will need to create distinct account level or domain scoped templates in each region for the account/domains."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"creating-and-using-templates","__idx":5},"children":["Creating and Using Templates"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can either create templates using the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/templates"},"children":["Template API"]}," or via the Mailgun application using our template builder. To learn about creating templates using the Template Builder interface, see ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://help.mailgun.com/hc/en-us/articles/360021380793-Email-Templates"},"children":["Email Templates"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Create a template using the API:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X POST -s --user 'api:YOUR_API_KEY' \\\n\n    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates \\\n\n    --form-string template='<div class=\"entry\"> <h1>{{title}}</h1> <div class=\"body\"> {{body}} </div> </div>' \\\n\n    -F name='template.test' \\\n\n    -F description='Sample template'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The response returns stored template information:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n\n  \"template\": {\n\n     \"createdAt\": \"Wed, 29 Aug 2018 23:31:13 UTC\",\n\n     \"description\": \"Sample template\",\n\n     \"name\": \"template.test\"\n\n  },\n\n  \"message\": \"template has been stored\"\n\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Creating an Account-Level Template via API"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X POST -s --user 'api:YOUR_API_KEY' \\\n\n    https://api.mailgun.net/v4/templates \\\n\n    --form-string template='<div class=\"entry\"> <h1>{{title}}</h1> <div class=\"body\"> {{body}} </div> </div>' \\\n\n    -F name='template.test' \\\n\n    -F description='Sample template'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The response returns stored template information:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n   \"message\": \"template has been stored\",\n   \"template\": {\n      \"createdAt\": \"Sat, 12 Nov 1955 06:38:00 UTC\",\n      \"createdBy\": \"user-supplied-value\",\n      \"description\": \"Sample template\",\n      \"id\": \"46565d87-68b6-4edb-8b3c-34554af4bb77\",\n      \"name\": \"template.test\",\n      \"version\": {\n         \"active\": true,\n         \"comment\": \"Version comment\",\n         \"createdAt\": \"Sat, 12 Nov 1955 06:38:00 UTC\",\n         \"headers\": {\n            \"From\": \"from@header.tld\",\n            \"Reply-To\": \"reply-to@header.tld\",\n            \"Subject\": \"Subject Value\"\n         },\n         \"id\": \"3efd2b85-0f41-4a1d-9898-05d7e7459c4a\",\n         \"tag\": \"tag\",\n         \"template\": \"\\u003chtml\\u003etemplate content\\u003c/html\\u003e\"\n      }\n   }\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"sending-messages-with-templates","__idx":6},"children":["Sending Messages with Templates"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Once your template is created, you can send messages using it:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -s --user 'api:YOUR_API_KEY' \\\n\n    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \\\n\n    -F from='Excited User <postmaster@YOUR_DOMAIN_NAME>' \\\n\n    -F to=recipient@example.com \\\n\n    -F subject='Hello there!' \\\n\n    -F template=\"template.test\" \\\n\n    -F t:variables='{\"title\": \"API documentation\", \"body\": \"Sending messages with templates\"}'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When sending MIME messages, pass template variables using the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["X-Mailgun-Template-Variables"]}," header instead of the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["t:variables"]}," parameter."]}]},"headings":[{"value":"Templates","id":"templates","depth":1},{"value":"Domain Level Templates","id":"domain-level-templates","depth":3},{"value":"Account Level Templates","id":"account-level-templates","depth":3},{"value":"Template ID","id":"template-id","depth":3},{"value":"Regions","id":"regions","depth":3},{"value":"Creating and Using Templates","id":"creating-and-using-templates","depth":2},{"value":"Sending Messages with Templates","id":"sending-messages-with-templates","depth":3}],"frontmatter":{"seo":{"title":"Using Templates","description":"How to manage Mailgun templates"}},"lastModified":"2026-12-01T19:22:40.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/mailgun/user-manual/templates/send-templates","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}