SendGrid
A send adapter template for delivering sign-in verification emails with SendGrid .
Installation
npm install @sendgrid/mailPlugin
Save this template as oberon/send.ts. Add its plugin export to your
server configuration.
oberon/send.ts
import "server-cli-only"
import { setApiKey, send } from "@sendgrid/mail"
import { USE_DEVELOPMENT_SEND_PLUGIN, type OberonPlugin } 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`,
})
},
},
})Environment variables
EMAIL_FROM=noreply@example.com
SENDGRID_API_KEY=your-sendgrid-api-keyThe template accepts SEND_SECRET if SENDGRID_API_KEY is unset. Verify your sender with SendGrid
before you send production email.
Last updated on