Supabase integration with MailerSend

Send and track emails from Supabase / PostgreSQL using MailerSend

See their pricing options.

Integration Support

See their documentation.

Supabase is an open-source Firebase alternative. Start your project with a Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, and Storage.

Using supabase-mailer with MailerSend

Step 1: Setup your private keys

Execute the following code in a SQL Query window:

INSERT INTO private.keys (key, value) values ('MAILERSEND_API_TOKEN', 'aaaaaaaaaa');

Where: aaaaaaaaaa is your Mailersend API Token

Step 2: Create the sendemailmessage function

Run the SQL code in 02_send_email_message.sql in a query window to create the PostgreSQL function. NOTE: You must modify this function for Mailersend. See the line:

email_provider text := 'mailersend';

Send a test message

You can send a test message from a query window like this:

select send_email_message('{
  "sender": "",
  "recipient": "",
  "subject": "This is a test message from my Supabase app!",
  "html_body": "<html><body>This message was sent from <a href=\"\">PostgreSQL</a> using <a href=\"\">Supabase</a> and <a href=\"\">Mailersend</a>.</body></html>"

If you've got everything setup correctly, you'll get a JSON object back with the Provider's response, such as:


At this point, you have everything you need to send messages. If you want to track your messages, read on.

Step 3: (Optional) Create the messages table (for tracking messages)

Run the SQL code from 03_setup_messages_table.sql in a query window to create the table that will store your email messages. When the sendemailmessage function senses that this table exists, it will store your messages in this table automatically when you send them.

Step 4: (Optional) Create messages to be sent later

This is completely optional, but if your workflow calls for you to create messages to be sent at a later time (say, according to a schedule or triggered from another event or table update), you can use the createemailmessage function.

Run the SQL code in 05_create_email_message.sql in a query window. Now you can create messages in the messages table like this:

select create_email_message('{
  "sender": "",
  "recipient": "",
  "subject": "This is a test message from my Supabase app!",
  "html_body": "<html><body>This message was originally created as \"ready\" in the messages table, then sent later from <a href=\"\">Supabase</a> using <a href=\"\">Mailersend</a>.</body></html>"

This will create a message in the messages table with messages.status = ready, and it will return the messageid of the message it just created. To send the message, call sendemailmessage later and pass it the messageid of this message. For example:

select send_email_message('{
  "messageid": "7f5fd9b7-cacb-4949-b8d4-a0398fa382e7"
Stop War! Help Ukraine! See what you can do