Skip to content

Commit

Permalink
feat(providers): Add Postmark email provider (#10512)
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Apr 8, 2024
1 parent 5b8bb9c commit c97431b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/core/src/providers/postmark.ts
@@ -0,0 +1,38 @@
import type { EmailConfig, EmailUserConfig } from "./index.js"
import { html, text } from "../lib/utils/email.js"

/** @todo Document this */
export default function Postmark(config: EmailUserConfig): EmailConfig {
return {
id: "postmark",
type: "email",
name: "Postmark",
from: "Auth.js <no-reply@authjs.dev>",
maxAge: 24 * 60 * 60,
async sendVerificationRequest(params) {
const { identifier: to, provider, url, theme } = params
const { host } = new URL(url)
if (!provider.apiKey) throw new TypeError("Missing Postmark API Key")
const res = await fetch("https://api.postmarkapp.com/email", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-Postmark-Server-Token": provider.apiKey,
},
body: JSON.stringify({
From: provider.from,
To: to,
Subject: `Sign in to ${host}`,
TextBody: text({ url, host }),
HtmlBody: html({ url, host, theme }),
MessageStream: "outbound",
}),
})

if (!res.ok)
throw new Error("Postmark error: " + JSON.stringify(await res.json()))
},
options: config,
}
}

0 comments on commit c97431b

Please sign in to comment.