Use Handlebars templates with the Trigger Email extension Stay organized with collections Save and categorize content based on your preferences.
If you specified a "Templates collection" parameter during configuration of theextension, you can create and manageHandlebars templates templates for your emails.
Template collection structure
Give each document a memorable ID that you use as thetemplate name in thedocuments you write to your templates collection.
The template document can include any of the following fields:
- subject: A template string for the subject of the email.
- text: A template string for the plaintext content of the email.
- html: A template string for the HTML content of the email.
- amp: A template string for theAMP4EMAIL content of the email.
- attachments: An array of attachments with template strings as values;Nodemailer options supported: utf-8 string, custom content type, URL, encoded string, data URI, and pre-generated MIME node (be aware that your email has no access to the cloud server's file system).
An example template might have an ID offollowing and content like:
{subject:"@{{username}} is now following you!",html:"Just writing to let you know that <code>@{{username}}</code> ({{name}}) is now following you.",attachments:[{filename:"{{username}}.jpg",path:"{{imagePath}}"}]}Send emails using templates
To deliver email using templates, when adding documents to your mail collection,include atemplate field withname anddata properties. For example,using ourfollowing template from above:
admin.firestore().collection("MAIL_COLLECTION").add({toUids:["abc123"],template:{name:"following",data:{username:"ada",name:"Ada Lovelace",imagePath:"https://example.com/path/to/file/image-name.jpg"},},});Template Partials
You can compose templates using reusablepartials by specifying{partial: true} in the template document. Each of the standarddata fields (subject,html,text, andamp) will be defined as a partialused only in its own environment. For example, a partial calledfooter mighthave data like:
{partial:true,html:"<p>This mail was sent by ExampleApp, Inc. <a href='https://example.com/unsubscribe'>Unsubscribe</a></p>",text:"This mail was sent by ExampleApp, Inc. Unsubscribe here: https://example.com/unsubscribe"}In another template, include the partial by referencing its name (document ID):
<p>This is my main template content, but it will use a common footer.</p>{{> footer }}Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-04 UTC.