Sendgrid
A send adapter template for delivering sign-in verification emails with SendGrid .
Installation
npm install @sendgrid/mailExample plugin
oberon/send.ts
import "server-cli-only"
import { setApiKey, send } from "@sendgrid/mail"
import {
USE_DEVELOPMENT_SEND_PLUGIN,
type OberonPlugin,
type OberonSendAdapter,
} from "@oberoncms/core"
const EMAIL_FROM = process.env.EMAIL_FROM
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY || process.env.SEND_SECRET
export const plugin: OberonPlugin = () => ({
name: "Sendgrid",
disabled: USE_DEVELOPMENT_SEND_PLUGIN,
adapter: {
sendVerificationRequest: async ({ email, token, url }) => {
if (!SENDGRID_API_KEY) throw new Error("No SENDGRID_API_KEY configured")
if (!EMAIL_FROM) throw new Error("No EMAIL_FROM configured")
setApiKey(SENDGRID_API_KEY)
await send({
to: email,
from: EMAIL_FROM,
subject: "One time login to Oberon CMS",
text: `Sign in with code\n\n${token}\n\n ${url} \n\n`,
})
},
} satisfies OberonSendAdapter,
})Environment variables
EMAIL_FROM=noreply@example.com
SENDGRID_API_KEY=your-sendgrid-api-keySEND_SECRET can be used as a fallback alias for SENDGRID_API_KEY.
Last updated on