Skip to content

Commit c97431b

Browse files
committed
feat(providers): Add Postmark email provider (#10512)
1 parent 5b8bb9c commit c97431b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { EmailConfig, EmailUserConfig } from "./index.js"
2+
import { html, text } from "../lib/utils/email.js"
3+
4+
/** @todo Document this */
5+
export default function Postmark(config: EmailUserConfig): EmailConfig {
6+
return {
7+
id: "postmark",
8+
type: "email",
9+
name: "Postmark",
10+
from: "Auth.js <[email protected]>",
11+
maxAge: 24 * 60 * 60,
12+
async sendVerificationRequest(params) {
13+
const { identifier: to, provider, url, theme } = params
14+
const { host } = new URL(url)
15+
if (!provider.apiKey) throw new TypeError("Missing Postmark API Key")
16+
const res = await fetch("https://api.postmarkapp.com/email", {
17+
method: "POST",
18+
headers: {
19+
Accept: "application/json",
20+
"Content-Type": "application/json",
21+
"X-Postmark-Server-Token": provider.apiKey,
22+
},
23+
body: JSON.stringify({
24+
From: provider.from,
25+
To: to,
26+
Subject: `Sign in to ${host}`,
27+
TextBody: text({ url, host }),
28+
HtmlBody: html({ url, host, theme }),
29+
MessageStream: "outbound",
30+
}),
31+
})
32+
33+
if (!res.ok)
34+
throw new Error("Postmark error: " + JSON.stringify(await res.json()))
35+
},
36+
options: config,
37+
}
38+
}

0 commit comments

Comments
 (0)