OWolf

2024-10-17 Web Development

How to Set Up Custom SMTP with Supabase and Resend: A Step-by-Step Guide

By O. Wolfson

This article provides a step-by-step guide on setting up a custom SMTP server with Supabase and Resend to send authenticated emails from your domain. You'll learn how to configure SMTP settings, verify your domain, and set up the necessary DNS records, including SPF, DKIM, and DMARC, ensuring secure and reliable email delivery for your application.


What is SMTP?

SMTP (Simple Mail Transfer Protocol) is a protocol used for sending and relaying emails across the internet. It ensures that emails from your server are properly sent and authenticated to reach the recipient’s inbox. SMTP servers manage email authentication, queuing, and delivery to ensure messages are delivered correctly.


How SMTP Relates to Domains and DNS Records

When using a custom domain (e.g., yourdomain.com) for sending emails, DNS records are critical for routing, verifying, and securing your email communications. The key DNS records are:

  • MX (Mail Exchanger) Records: These direct where to send incoming mail.
  • SPF (Sender Policy Framework) Records: These help prevent email spoofing by specifying which servers can send emails on behalf of your domain.
  • DKIM (DomainKeys Identified Mail) Records: These add a cryptographic signature to your emails, ensuring they haven’t been altered.
  • DMARC (Domain-based Message Authentication, Reporting & Conformance): This allows you to set policies for handling emails that fail SPF or DKIM checks.

Step-by-Step Setup: Custom SMTP with Supabase and Resend

Step 1: Configure SMTP Credentials in Resend

  1. Create an account on Resend or your chosen email service provider.

  2. Add your domain to Resend and configure DNS settings. Resend will provide the necessary DNS records for verification:

    • MX Record: Points to Resend's SMTP servers for incoming mail.
    • SPF Record: Authorizes Resend to send emails on behalf of your domain.
    • DKIM Record: Provides cryptographic authentication for your emails.
  3. Add the DNS records to your DNS provider (such as Vercel, Cloudflare, etc.). For example:

txt
Name: resend._domainkey
Type: TXT
Value: <DKIM Public Key>
TTL: 60
  1. Wait for DNS propagation (this can take several minutes to hours). Once the records propagate, Resend will verify the domain.

  2. Once the domain is verified, note the following SMTP details:

    • SMTP Host: smtp.resend.com
    • SMTP Port: 465 or 587
    • Username: Provided by Resend
    • Password: Provided by Resend

Step 2: Configure Custom SMTP in Supabase

  1. Access your Supabase dashboard and go to the Authentication section.

  2. Under the Email or Custom SMTP tab, input the following details:

    • SMTP Host: smtp.resend.com
    • SMTP Port: 465 (or 587)
    • Username: Provided by Resend
    • Password: Provided by Resend
    • Sender Email: For example, team@yourdomain.com
    • Sender Name: This is the display name seen by the email recipient.
  3. Save and encrypt your SMTP credentials (handled automatically by Supabase).


Step 3: Test the SMTP Configuration

  1. Once your DNS records have fully propagated and the domain is verified, test sending an email from your application to ensure the SMTP configuration is correct.
  2. Verify that the emails are delivered to the inbox (not flagged as spam) and appear with the correct sender name and email address.

Conclusion

By following these steps, you can successfully set up custom SMTP with Supabase and Resend. With the proper DNS records (SPF, DKIM, and MX) and domain verification, your emails will be authenticated, ensuring higher deliverability and security. This setup allows for professional, branded email communication for your application.