Skip to content

Commit 9b5abd2

Browse files
committed
Add unsend sdk
1 parent b01b6cf commit 9b5abd2

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"superjson": "^2.2.1",
6868
"tailwind-merge": "^2.2.0",
6969
"tailwindcss-animate": "^1.0.7",
70+
"unsend": "^1.0.0",
7071
"vaul": "^0.8.9",
7172
"web-push": "^3.6.7",
7273
"zod": "^3.22.4",

pnpm-lock.yaml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server/mailer.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { type User } from 'next-auth';
2+
import { Unsend } from 'unsend';
23
import { Resend } from 'resend';
34
import { env } from '~/env';
45

56
const resend = new Resend(env.RESEND_API_KEY);
67

8+
const unsend = new Unsend(env.UNSEND_API_KEY);
9+
710
export async function sendSignUpEmail(email: string, token: string, url: string) {
811
const { host } = new URL(url);
912

@@ -47,31 +50,20 @@ export async function sendFeedbackEmail(feedback: string, user: User) {
4750

4851
async function sendMail(email: string, subject: string, text: string, html: string) {
4952
try {
50-
if (env.UNSEND_API_KEY && env.UNSEND_URL) {
51-
const resp = await fetch(`${env.UNSEND_URL}/emails`, {
52-
method: 'POST',
53-
headers: {
54-
'Content-Type': 'application/json',
55-
Authorization: `Bearer ${env.UNSEND_API_KEY}`,
56-
},
57-
body: JSON.stringify({
58-
from: 'hello@auth.splitpro.app',
59-
to: email,
60-
subject,
61-
text,
62-
html,
63-
}),
53+
if (env.UNSEND_API_KEY) {
54+
const response = await unsend.emails.send({
55+
from: 'hello@auth.splitpro.app',
56+
to: email,
57+
subject,
58+
text,
59+
html,
6460
});
6561

66-
if (resp.status === 200) {
67-
console.log('Email sent using unsend', await resp.json());
62+
if (response.data) {
63+
console.log('Email sent using unsend', response.data);
6864
return;
6965
} else {
70-
console.log(
71-
'Error sending email using unsend, so fallback to resend',
72-
resp.status,
73-
resp.statusText,
74-
);
66+
console.log('Error sending email using unsend', response.error);
7567
}
7668
}
7769
} catch (error) {

0 commit comments

Comments
 (0)