You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何自定义Docker自托管Supabase的邮件模板?

解决Supabase非自托管环境下自定义邮件模板的方法

Supabase托管版(非自托管)目前没有直接在控制台编辑内置邮件模板的入口,但可以通过以下两种官方支持的方案实现自定义需求:

方案1:用Edge Functions完全接管邮件发送逻辑

通过编写Edge Functions替代Supabase Auth的内置邮件服务,实现100%自定义:

  • 先在控制台的「Auth -> 设置 -> Email模板」页面,关闭确认邮箱、重置密码等自动邮件触发开关
  • 用命令初始化Edge Function:supabase functions new send-custom-email
  • 在函数中集成第三方邮件服务(如SendGrid、Resend),编写自定义HTML邮件模板
  • 配合Auth Hooks(如before_sign_up、before_password_reset)触发自定义函数发送邮件

示例核心代码片段:

import { createClient } from '@supabase/supabase-js'
import * as sgMail from '@sendgrid/mail'

sgMail.setApiKey(Deno.env.get('SENDGRID_API_KEY')!)

Deno.serve(async (req) => {
  const { email, token, type } = await req.json()
  const template = getCustomTemplate(type, token)
  
  await sgMail.send({
    to: email,
    from: 'your-domain@example.com',
    subject: type === 'verify' ? '验证你的邮箱' : '重置你的密码',
    html: template
  })
  
  return new Response(JSON.stringify({ success: true }), { status: 200 })
})

function getCustomTemplate(type: string, token: string) {
  if (type === 'verify') {
    return `<html><body><h1>欢迎加入</h1><p>点击<a href="https://your-domain.com/verify?token=${token}">这里</a>完成邮箱验证</p></body></html>`
  }
  // 重置密码模板
  return `<html><body><h1>重置密码</h1><p>点击<a href="https://your-domain.com/reset?token=${token}">这里</a>设置新密码</p></body></html>`
}

方案2:配置自定义SMTP服务器(有限自定义)

如果仅需修改邮件样式、品牌信息,可通过自定义SMTP实现:

  • 在控制台「Auth -> 设置 -> SMTP」页面,配置自己的SMTP服务器(如Gmail、SendGrid)
  • Supabase会将邮件内容发送到你的SMTP服务器,你可在SMTP服务端设置模板替换规则(部分邮件服务商支持)
  • 局限性:无法完全自定义邮件核心内容结构,仅能调整样式类信息

关键说明

Supabase托管版暂未开放内置邮件模板的直接编辑权限,上述两种是当前可行的官方支持方案,其中Edge Functions能提供最灵活的自定义控制。

内容的提问来源于stack exchange,提问作者Francesco De Caro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 11:46:01