-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resend has been plagued with security issues lately, and I can no longer recommend using them for production apps, especially ones which send authentication links via email. Postmark has been a leader in the space for a long time and is one of the easiest and most reliable email services to use.
- Loading branch information
Showing
10 changed files
with
62 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { env } from "@/env" | ||
|
||
export type SendEmailParams = { | ||
to: string | ||
from: string | ||
subject: string | ||
html?: string | ||
text?: string | ||
headers?: Record<string, string> | ||
} | ||
|
||
/** | ||
* Sends an email using Postmark's API. | ||
* | ||
* @see {@link https://postmarkapp.com/developer/user-guide/send-email-with-api} | ||
*/ | ||
export async function sendEmail({ | ||
to, | ||
from, | ||
subject, | ||
html, | ||
text, | ||
headers | ||
}: SendEmailParams) { | ||
const response = await fetch("https://api.postmarkapp.com/email", { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
"X-Postmark-Server-Token": env.POSTMARK_API_KEY | ||
}, | ||
body: JSON.stringify({ | ||
From: from, | ||
To: to, | ||
Subject: subject, | ||
HtmlBody: html, | ||
TextBody: text, | ||
MessageStream: "outbound", | ||
Headers: | ||
headers && | ||
Object.entries(headers).map(([key, value]) => ({ | ||
Name: key, | ||
Value: value | ||
})) | ||
}) | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error(`Email send failed: ${response.status}`) | ||
} | ||
|
||
return response.json() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters