escwxyz

payload email template

by escwxyz
Email
v3
^3.37.0
MIT

Overview

Summary generated from the README

Adds an email-templates collection where editors build emails from blocks such as heading, button, container, image, row, section and text. Templates support dynamic macros, localization and a device preview tab. HTML and plain text output is available through a REST endpoint or a local API function. Requires Payload 3.37 or newer.

Features

  • Block-based template builder with nestable layout blocks
  • Macros for variables, config values, dates, functions, conditions and loops
  • Preview tab with device breakpoints and zoom controls
  • Generate endpoint returning HTML and plain text versions
  • Local API function to render templates on the server
  • Automatic localization of text fields when Payload localization is enabled

Use cases

  • Build transactional emails like welcome or order confirmations that editors can edit without code
  • Send personalized, localized emails by passing runtime macro context at render time
  • Render email HTML and plain text on the server before passing to an email provider

From the author

A plugin for Payload CMS to create email templates based on React Email

Installation

npm i payload-email-template

33

Stars

2

Forks

9

Open Issues

1 years ago

Last Updated

27

Weekly Downloads

v1.2.1

npm Version

330.0 KB

Unpacked Size

2

Dependencies

GitHub stars

330 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 202633
Dec 5, 202633
Dec 4, 202633
Dec 3, 202633
Dec 2, 202633
Dec 1, 202633
Nov 30, 202633
Nov 29, 202633
Nov 28, 202633
Nov 27, 202633
Nov 26, 202633
Nov 25, 202633
Nov 24, 202633
Nov 23, 202633
Nov 22, 202633
Nov 21, 202633
Nov 20, 202633
Nov 19, 202633
Nov 18, 202633
Nov 17, 202633
Nov 16, 202633
Nov 15, 202633
Nov 14, 202633
Nov 13, 202633
Nov 12, 202633
Nov 11, 202633
Nov 10, 202633
Nov 9, 202633
Nov 8, 202633
Nov 7, 202633
Nov 6, 202633
Nov 5, 202633
Nov 4, 202633
Nov 3, 202633
Nov 2, 202633
Nov 1, 202633
Oct 31, 202633
Oct 30, 202633
Oct 29, 202633
Oct 28, 202633
Oct 27, 202633
Oct 26, 202633
Oct 25, 202633
Oct 24, 202633
Oct 23, 202633
Oct 22, 202633
Oct 21, 202633
Oct 20, 202633
Oct 19, 202633
Oct 18, 202633
Oct 17, 202633
Oct 16, 202633
Oct 15, 202633
Oct 14, 202633
Oct 13, 202633
Oct 12, 202633
Oct 11, 202633
Oct 10, 202633
Oct 9, 202633
Oct 8, 202633
Oct 7, 202633
Oct 6, 202633
Oct 5, 202633
Oct 4, 202633
Oct 3, 202633
Oct 2, 202633
Oct 1, 202633
Sep 30, 202633
Sep 29, 202633
Sep 28, 202633
Sep 27, 202633
Sep 26, 202633
Sep 25, 202633
Sep 24, 202633
Sep 23, 202633
Sep 22, 202633
Sep 21, 202633
Sep 20, 202633
Sep 19, 202633
Sep 18, 202633
Sep 17, 202633
Sep 16, 202633
Sep 15, 202633
Sep 14, 202633
Sep 13, 202633
Sep 12, 202633
Sep 11, 202633
Sep 10, 202633
Sep 9, 202633
Sep 8, 202633
Sep 7, 202633
npm weekly downloads

28−42 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202628
Dec 5, 20268
Dec 4, 20266
Dec 3, 20266
Dec 2, 20267
Dec 1, 202617
Nov 30, 202619
Nov 29, 202623
Nov 28, 202623
Nov 27, 202623
Nov 26, 202623
Nov 25, 202623
Nov 24, 202614
Nov 23, 202613
Nov 22, 202618
Nov 21, 202624
Nov 20, 202625
Nov 19, 202626
Nov 18, 202635
Nov 17, 202635
Nov 16, 202637
Nov 15, 202630
Nov 14, 202627
Nov 13, 202626
Nov 12, 202634
Nov 11, 202626
Nov 10, 202630
Nov 9, 202627
Nov 8, 202626
Nov 7, 202629
Nov 6, 202628
Nov 5, 202620
Nov 4, 202633
Nov 3, 202629
Nov 2, 202635
Nov 1, 202643
Oct 31, 202637
Oct 30, 202638
Oct 29, 202636
Oct 28, 202621
Oct 27, 202620
Oct 26, 202615
Oct 25, 202659
Oct 24, 202690
Oct 23, 202688
Oct 22, 202692
Oct 21, 2026114
Oct 20, 2026116
Oct 19, 2026119
Oct 18, 202665
Oct 17, 202647
Oct 16, 202662
Oct 15, 202677
Oct 14, 202663
Oct 13, 202661
Oct 12, 202657
Oct 11, 202663
Oct 10, 202656
Oct 9, 202642
Oct 8, 202624
Oct 7, 202617
Oct 6, 202624
Oct 5, 202626
Oct 4, 202621
Oct 3, 202620
Oct 2, 202625
Oct 1, 202625
Sep 30, 202628
Sep 29, 202638
Sep 28, 202637
Sep 27, 202635
Sep 26, 202633
Sep 25, 202630
Sep 24, 202631
Sep 23, 202638
Sep 22, 202633
Sep 21, 202639
Sep 20, 202687
Sep 19, 202699
Sep 18, 2026131
Sep 17, 2026164
Sep 16, 2026217
Sep 15, 2026211
Sep 14, 2026206
Sep 13, 2026163
Sep 12, 2026166
Sep 11, 2026150
Sep 10, 2026130
Sep 9, 202668
Sep 8, 202665
Sep 7, 202670

Each point is npm's rolling 7-day download count.

Health Score

0/100Archived

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1012168829-root.svg)](https://payloaddirectory.dev/plugins/1012168829-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1012168829-root"><img src="https://payloaddirectory.dev/badge/1012168829-root.svg" alt="Payload Directory"></a>
Updated Nov 24, 2025Created Jul 1, 2025Published Aug 29, 2025

README

Payload Email Template Plugin 🚀

npm version npm downloads MIT License


A powerful, visual, and block-based email template builder plugin for Payload CMS — built on top of React Email. Design beautiful, dynamic, and localized email templates with ease! ✨


✨ Features

  • 🧩 Visual, block-based email template builder (no raw JSX required)
  • 🏗️ Custom blocks: Heading, Button, Container, Image, Row, Section, Text, and more
  • 🔧 Dynamic macros: Variables, functions, dates, conditions, loops, and config values
  • 👀 Preview: See your email as you build, with device and zoom controls
  • 🌍 Localization: Localize templates and content
  • 🔌 API endpoints: Generate both HTML and PlainText before sending your email

📦 Installation

pnpm add payload-email-template
# or
yarn add payload-email-template
# or
npm install payload-email-template

🚀 Getting Started

Add the plugin to your Payload config in the plugins array:

import { emailTemplatePlugin } from 'payload-email-template'

export default buildConfig({
  // ...other config
  plugins: [
    emailTemplatePlugin({
      enabled: true,
      imageCollectionSlug: 'media', // (optional) collection for image uploads
      previewBreakpoints: [
        // (optional) default breakpoints
        { name: 'mobile', label: 'Mobile', width: 375, height: 667 },
        { name: 'desktop', label: 'Desktop', width: 1440, height: 900 },
      ],
      disableStyle: false, // (optional) allow custom style overrides, default: false
      macros: {
        // (optional) dynamic content for variables, functions, and config
        variables: {
          companyName: 'Your Company',
          user: { firstName: 'John', lastName: 'Doe' },
        },
        functions: {
          greet: (name) => `Hello, ${name}!`,
          formatPrice: (price) => `$${price.toFixed(2)}`,
        },
        config: {
          appName: 'My App',
          version: '1.0.0',
        },
      },
      // ...other options
    }),
  ],
})

🖼️ Demo

Demo 1

Demo 2


⚙️ Plugin Options

OptionTypeDefaultDescription
enabledbooleantrueEnable/disable the plugin
imageCollectionSlugstring'media'Collection slug for image uploads
previewBreakpointsarraysee exampleDevice preview sizes for the preview tab
disableStylebooleanfalseDisable custom style overrides
macrosobject{}Dynamic content configuration (variables, functions, config)
endpointAccessAccess({req}) => Boolean(req.user)Default access control for the /api/email-templates/:id/generate endpoint
collectionAccessAccess{ read: ({req}) => Boolean(req.user) }Default access control for email-templates collection

🛠️ Usage

🧱 Blocks

Configure blocks (Heading, Button, Container, etc.) to build your template. Each block has configurable fields (content, style, alignment, etc.). Blocks can be nested for complex layouts.

🌍 Localization

If you enable localization in your Payload config, the plugin will automatically make text-related template fields localizable.

👀 Preview

The template can be previewed in the Preview tab. You can also use the controls to toggle mode, device, and zoom.


🔌 API Endpoints

Generate Email Template

You can trigger rendering the email template by sending a POST request to the following endpoint:

POST /api/email-templates/:id/generate

You will receive both html and plainText versions of the template:

{
  "html": "<html>...</html>",
  "plainText": "..."
}

Then you can send it via your email provider.


⚙ Local Api

Generate Email Template

It's also possible to render the email template by calling renderEmailTemplate directly in the back-end, skipping the http request in that case.

import { renderEmailTemplate } from "payload-email-template"

// const emailTemplate = await req.payload.find({
//   collection: 'email-templates',
//   ...
// })

const html = await renderEmailTemplate({
  data: emailTemplate,
  locale: 'en',
  format: 'html',
  macroContext: {
    variables: { ... },
    functions: { ... },
    config: { ... }
  }
})


🔧 Macros

The plugin supports powerful dynamic content through macros that can be used in email subjects, headings, and text blocks.

Macro Types

1. Variables - {{variableName}}

Access data from your macro configuration:

{{companyName}} → "Acme Corporation"
{{user.firstName}} → "John"
2. Config Values - {{@config('key')}}

Access plugin configuration values:

{{@config('appName')}} → "My Awesome App"
{{@config('version')}} → "1.0.0"
3. Date Functions - {{@date('format')}}

Format current date and time:

{{@date('YYYY-MM-DD')}} → "2024-01-15"
{{@date('MMMM Do, YYYY')}} → "January 15th, 2024"
4. Functions (Server-side only)

Transform data with custom functions:

{{@uppercase('hello')}} → "HELLO"
{{@greet('John')}} → "Hello, John!" (if configured)
5. Conditional Content

Show content based on conditions:

  • Set up conditions in the macro block interface
  • Define content for true/false scenarios
  • Useful for personalized content
6. Loops

Repeat content for data collections:

  • Configure collection data source
  • Define template for each item
  • Great for product lists, etc.

Usage Locations

✅ Email Subjects: "Welcome to {{companyName}}, {{user.firstName}}!"

✅ Heading Blocks: Mix text, links, and macros in headings

✅ Text Blocks: Inline macros alongside regular text and links

✅ Macro Blocks: Dedicated blocks for complex conditions and loops

Runtime Context

You can also pass runtime macro context when generating emails:

// POST /api/email-templates/:id/generate
{
  "macroContext": {
    "variables": {
      "user": { "firstName": "Jane" },
      "orderTotal": "$99.99"
    }
  }
}

Runtime context takes precedence over plugin configuration.


🤝 Contributing

Contributions are welcome! Please open issues or pull requests for bug fixes, features, or documentation improvements.


📄 License

MIT

Similar plugins