In this post, I would like to explain how to send emails using a Firebase extention, called Trigger Email. With that extention, it is possible to send emails by simple creating documents on Cloud Firestore.

firestore


Setting up Gmail account

Trigger Email extention uses SMTP to send emails, but SMTP is disabled by default for Gmail accounts. So we need to enable SMTP for Gmail here.

Setting up Trigger Email

  1. Visit this link and choose a Google Cloud project to enable this extention.

  2. Click Next for step 1, 2 and 3.

  3. At Step 4, we need to fill in two fields: SMTP connection URI and Default FROM address. SMTP URI for gmail is in the form of:

    smtps://<email>:<password>@smtp.gmail.com:465
    

    Please replace <email> and <password> with the Gmail account you want to use.

  4. Next field is Default FROM address, which will be the same as the <email> at step 3. So if you have a Gmail account example@gmail.com with its password 123456, the filled in fields would look like in the image below:

    Only SMTP URI and FROM adress is required

  5. You can click on Install Extention button at the end of the page. This will bring you to Installed Extentions page.

    The deployment will take around 5 minutes as indicated.

  6. After the installation done, we need to create a collection called mail in Firestore.

  7. Next, we will add a document in mail collection that will trigger the extention. The document is in the form of json below. Make sure to replace to field with the receiver email.

    1{
    2"to": "example@gmail.com",
    3"message" : { 
    4    "subject" : "Hello", 
    5    "text" : "world"
    6}
    7}
    

    Here is how it looks like on Firestore dashboard:

    firestore

  8. After you hit Save the extention will process the document and you will receive an email in about 30 seconds.