How to install and use Trigger Email Extension from Firebase?

Alex Mamo
Firebase Tips & Tricks
6 min readJun 7, 2021

--

This Extension composes and sends an email based on the content of a document that is written to a specified Cloud Firestore collection.

There a lot of cases in which we need to send information to our users via email. Fortunately, Firebase has created an Extension called Trigger Email, that can help us achieve exactly that. It’s really, really easy to install and use.

How does it work?
This extension will compose and send an email as soon as a new document is created into a selected collection in Firestore. You can call this collection “mail”, “mails” or “emails”, or whatever you want. Even if doesn’t already exist, it will be automatically created. To be able to send an email, the document that is written should contain at least three fields, the email address, and a message which in terms is composed of two properties, one is subject and the other one is HTML. You can add such a document using:

admin.firestore().collection('emails').add({
to: 'name@email.com',
message: {
subject: 'Hello, World!',
html: 'This is the<code>HTML</code> email body.',
},
})

Being in an HTML format, the body of the email can be customized as you like. There is also an option for templates, so you can use a custom design when sending emails. So optionally you can configure this Extension to render emails using Handlebar templates. Each template is also a document stored in a Cloud Firestore collection.

--

--