Firebase
Firebase is Google’s open-source mobile and web app development platform that provides a suite of tools and services for building, managing, and scaling web and mobile applications.
In this article, you’ll learn how to install the Mailtrap Firebase Extension, which allows you to send transactional emails from your Firebase project via Mailtrap without building or maintaining your own cloud functions.
Prerequisites:
A Mailtrap account with a verified sending domain
A Mailtrap API token from the API Tokens page
A Firebase project on the Blaze (pay-as-you-go) plan
Step 1. Install the Firebase extension
To install the Firebase extension, you have two options. Namely:
Option 1: Firebase console
Use the quick install or visit the official Firebase Extension Marketplace page and click Install.
Option 2: Firebase CLI
With the Firebase CLI installed, run the following command in your terminal:
firebase ext:install mailtrap/mailtrap-email --project=YOUR_PROJECT_IDStep 2. Configure Firebase
During installation, you'll be prompted to configure the following parameters:
MAILTRAP_API_TOKEN
Your Mailtrap API token. It will be stored securely in Google Secret Manager.
MAIL_COLLECTION
The Firestore collection to watch for new documents. Default: mail
DEFAULT_FROM_EMAIL
The default sender email address.
DEFAULT_FROM_NAME
The default sender name (optional).
Step 3. How to trigger an email
To trigger an email, add a document to your configured Firestore collection. The extension will pick it up and send it through Mailtrap automatically. Here are some code snippets you can use:
Furthermore, you can create and manage templates directly in the Mailtrap UI without any coding required, and they’ll be accessible to your whole team.

Step 4. Check whether the email has been delivered
In Firestore
After the extension processes the document, it automatically updates it with a delivery field:
Possible states of the delivery field:
delivery.state– PENDING, PROCESSING, SUCCESS, ERRORdelivery.error– Error message if faileddelivery.messageIds– Mailtrap message IDs on success
In Mailtrap
Go to Email Logs in your Mailtrap account to see full delivery details, open and click tracking, and the complete event history for each message.

Configuring Firestore Security Rules
You must pay attention to Security Rules so that email delivery is appropriately secure. Almost certainly you want the mail collection to be forbidden to users and only accessible to functions. Then you trigger it from your backend code.
To control who can add documents to your mail collection, you can set up Firestore Security Rules by copying the following code snippet into the firestore.rules file or directly in the console under Firestore Database → Rules:
Note that if you do make it accessible to users, they could trigger email delivery as much as they want, so it's up to you to develop a suitable authorization model.
Billing
This extension uses the following Firebase services which may have associated charges:
Cloud Firestore
Cloud Functions (2nd gen)
Secret Manager
This extension also uses Mailtrap's email sending service, which has its own pricing.
Last updated
Was this helpful?

