How to send emails from Supabase

The ability to send our users emails is a crucial part of any app development. We may want to do this in app for a number of reasons, so knowing how to send emails from Supabase will provide us the freedom of doing this without additional third party tools and ensuring our data is all staying on our back end.

What do we need to send emails from Supabase

There are three elements needed to make this work.

  1. The http extension needs to be enabled in our Supabase project
  2. We will need to use the code provided in the Supabase-Mailer project on GitHub 
  3. Access to an email sending providers API to actually send the messages.

The video below runs through in detail how to use these elements together to send emails to our users. All of the code used is available in the GitHub projects linked above.

Advanced considerations when sending emails from Supabase

The tutorial here focuses on the email being sent to our users when a PostgreSQL function is called from within our applications. This could equally easily be triggered by using a trigger function within our Supabase instance when a table is updated, such as the sum of values in a column updating for example. In our example, we could send the email to the users in the project team list column of our projects table every time there is a change to that project in the table. We can set up a trigger for this.

In addition we are only sending simple text emails for notification purposes in this example. An advanced avenue to explore would be to send full html style templates from your sending provider by connecting to the template from the Supabase http extension and populating it with the information contained in your JSON message. This would be ideal for marketing and transactional emails.

Final thoughts on sending emails from Supabase

The Supabase_Mailer project is a great way of getting this functionality up and running quickly. Everything is done for you and if you follow the instructions you will be sending your users emails from Supabase in no time at all. The advanced considerations will take this to the next level and you should be able to have fully automated email delivery no matter what front end framework you are using.