Hi,
Can you provide and example of how to use templates with Trigger Email extension ?
What I'm not sure about :
Some code example would be great :)
Thanks a lot
Hi @NLegendre - this example may help you: https://github.com/firebase/extensions/blob/master/firestore-send-email/POSTINSTALL.md#using-templates
To summarise:
Create a new document in Firestore for your templates, for example for a template called "Following", create a new document in templates/following:
{
subject: "@{{username}} is now following you!",
html: "Just writing to let you know that <code>@{{username}}</code> ({{name}}) is now following you."
}
When adding a new document to your mail collection, pass in a template name with the data which will be injected:
toUids: ['abc123'],
template: {
name: 'following',
data: {
username: 'ada',
name: 'Ada Lovelace'
}
}
On the logical "if statement", it should work yes, however I'll check this myself too and make sure it is working.
That's perfect !
Thank you very much !
tried sending an attachment using the array field 'attachments' in template collection. But the email got delivered with the attachment. Does anyone know if the extension is supposed to work with an attachment in the template?
For some reason my emails still cant pick up the templates. I have configured just like above templates collection is created and i have added the object.
db.collection('templates').add({
toUids: ['abc123'],
template: {
name: 'following',
data: {
username: 'ada',
name: 'Ada Lovelace'
}
}
})
When I try to add the below to mail I the this error.

{
to: '[email protected]',
message: {
subject: 'Hi there!'
},
template: {
name: 'following'
}
}
SOLVED: It does not look for template.name in the object you create the template document with as the documentation mislead me to think. The plugin actually looks for a matching document id for your template (i.e. template: name: 'oA3SXV3q3hU8imLqbet3'}). I hope this saves someone else 3 hours of playing around.
Most helpful comment
Hi @NLegendre - this example may help you: https://github.com/firebase/extensions/blob/master/firestore-send-email/POSTINSTALL.md#using-templates
To summarise:
Create a new document in Firestore for your templates, for example for a template called "Following", create a new document in
templates/following:When adding a new document to your mail collection, pass in a template name with the data which will be injected:
On the logical "if statement", it should work yes, however I'll check this myself too and make sure it is working.