Blogs

3 Ways to Send Emails with Supabase

3 Ways to Send Emails with Supabase

3 Ways to Send Emails with Supabase

Jun 5, 2024

We discuss and implement 3 solutions for including email notifications in your Supabase project using NodeJS.

While Supabase has a built-in email functionality, but only for authentication emails and only at a limited rate limit. There are several 3rd-party solutions to send email notifications from Supabase using Edge Functions. We will cover 3 of them using NodeJS:

  • NotificationAPI: 10k free emails, built-in email editor

  • SendGrid: 3k free emails

  • Resend: 3k free emails

If you are not familiar with Edge Functions, you can follow our step-by-step email + edge function guide here.

If you are familiar with Edge Functions, continue reading:

NotificationAPI

NotificationAPI is an all-in-one notification system with capabilities such as:

  • Multi-channel support: Email, SMS, In-App

  • Template Editors

  • User Preferences Management

After signing up, the dashboard helps you visually design a notification so you don't have to write email HTML/CSS in your code manually.

First, install NotificationAPI's server SDK:

npm install notificationapi-node-server-sdk

Here's an example of a Supabase Edge Function that sends a welcome notification using NotificationAPI:

import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
import notificationapi from "npm:notificationapi-node-server-sdk";

notificationapi.init(
  Deno.env.get("NOTIFICATIONAPI_CLIENT_ID"),
  Deno.env.get("NOTIFICATIONAPI_CLIENT_SECRET")
);

serve(async (req) => {
  const { firstName, userId, email, phoneNumber } = await req.json();

  await notificationapi.send({
    notificationId: "welcome",
    user: {
      id: email,
      email: email,
      number: phoneNumber,
    },
    mergeTags: {
      // these are the dynamic parameters that are used in the notificaiton content
      firstName,
    },
  });

  return new Response(JSON.stringify({ success: true }), {
    headers: { "Content-Type": "application/json" },
  });
});

You can find the complete code for this guide in our GitHub repository.

SendGrid

SendGrid is an email-only solution, but it's good for both marketing and transactional emails.

After creating an account with SendGrid, you’ll need to complete their onboarding requirements, such as:

  • Creating a sender identity

  • Having either a domain or email address you wish to use to send emails

Make sure to select the Web API option during their onboarding when asked which method you will use to send emails.

Here is the sample code to send an email using SendGrid:

const sendgrid = require('@sendgrid/mail');
// Make sure to use .env files for API keys, etc
const sendgridKey = process.env.SENDGRID_KEY;
const sendgridSender = process.env.SENDGRID_ADDRESS;

const sendEmail = async (req, res) => {
  // Connecting to SendGrid
  sendgrid.setApiKey(sendgridKey);
  /* Creating our mail object for SendGrid 
  Replace these values with your own */
  const mail = {
    to: `your_email@mail.com`,
    from: sendgridSender,
    subject: `Sending an email using SendGrid`,
    html: `<strong>We sent this email using SendGrid!</strong>`
  };
  // Sending our email
  sendgrid.send(mail);
};

return sendEmail();

Notice that, unlike NotificationAPI, you need to code your own email template using HTML & CSS inside your Supabase Edge Function.

Resend

Resend is an email-only service very similar to SendGrid, also geared towards both marketing and transactional notifications.

This solution requires you to have your own domain in order to send emails, along with a more extensive setup, which will take the longest of our solutions to integrate.

Here's an example of how to send emails using Resend from Supabase Edge Functions:

import { Resend } from 'resend';
// Make sure to use .env files for API keys, etc
const resendKey = process.env.RESEND_KEY;

const sendEmail = async (req, res) => {
  // Connecting to Resend
  const resend = Resend(resendKey);
  await resend.emails.send({ 
    /* Creating our Resend mail object
    Replace these values with your own */
    from: `Testing <name@your_domain.com>`,
    to: [`your_email@mail.com`],
    subject: `Test email`,
    text: `We sent this email using Resend!`,
  });
};

return sendEmail();

Notice that, unlike NotificationAPI, you need to code your own email template using HTML & CSS inside your Supabase Edge Function.

Conclusion

If you are looking to send marketing emails, you are better off using Resend or SendGrid. But if you focus more on transactional notifications (product-to-user notifications), NotificationAPI is a stronger tool because of its:

  • Email and other template editors to make implementation quicker

  • Bigger free tier

  • Support for other channels: SMS, In-App, Push, and more.

Launch Notifications In Minutes.

NotificationAPI Software Inc.

#0200-170 Water St.,

St. John's, NL

Canada A1C 3B9


hello@notificationapi.com


Proud sponsors of:

  • TechNL.ca

  • Get Building

  • DataForge Hackathon

  • BadAdvice Podcast

GET OUR NEWSLETTER

© 2020 - 2025 NotificationAPI Software Inc.

Launch Notifications In Minutes.

NotificationAPI Software Inc.

#0200-170 Water St.,

St. John's, NL

Canada A1C 3B9


hello@notificationapi.com


Proud sponsors of:

  • TechNL.ca

  • Get Building

  • DataForge Hackathon

  • BadAdvice Podcast

GET OUR NEWSLETTER

© 2020 - 2025 NotificationAPI Software Inc.

Launch Notifications In Minutes.

NotificationAPI Software Inc.

#0200-170 Water St.,

St. John's, NL

Canada A1C 3B9


hello@notificationapi.com


Proud sponsors of:

  • TechNL.ca

  • Get Building

  • DataForge Hackathon

  • BadAdvice Podcast

Join Our Newsletter

© 2020 - 2025 NotificationAPI Software Inc.