Skip to content

Commit

Permalink
Remove ability to email multiple people
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerdavis1 committed Dec 6, 2023
1 parent 9b5dc49 commit c6f32eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions app/utils/email.server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { type ReactElement } from 'react'
import { renderAsync } from '@react-email/components'
import { siteEmailAddressWithName } from '~/data.ts'
import { Resend } from 'resend';
import { Resend } from 'resend'

const resend = new Resend(process.env.RESEND_API_KEY);
const resend = new Resend(process.env.RESEND_API_KEY)

export async function sendEmail({
react,
...options
}: {
to: string | string[]
to: string
subject: string
attachments?: { filename?: string, path?: string, content?: string | Buffer }[]
attachments?: {
filename?: string
path?: string
content?: string | Buffer
}[]
} & (
| { html: string; text: string; react?: never }
| { react: ReactElement; html?: never; text?: never }
Expand All @@ -20,7 +24,7 @@ export async function sendEmail({
const from = siteEmailAddressWithName

const email = {
from,
from,
...options,
...(react ? await renderReactEmail(react) : null),
}
Expand Down Expand Up @@ -57,24 +61,24 @@ export async function sendEmail({
html: email.html,
text: email.text,
attachments: email.attachments,
});
})

return {
status: 'success',
data: response,
} as const

// Catch full exception
} catch (e : any) {
console.error('🔴 error sending email:', JSON.stringify(email))
} catch (e: any) {
console.error('🔴 error sending email:', JSON.stringify(email))
return {
status: 'error',
error: {
message: e.message || 'Unknown error',
code: e.code || 'Unknown code',
response: e.response || 'Unknown response',
}
}
status: 'error',
error: {
message: e.message || 'Unknown error',
code: e.code || 'Unknown code',
response: e.response || 'Unknown response',
},
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function createFixture(
}

export const emailSchema = z.object({
to: z.union([z.string(), z.array(z.string())]),
to: z.string(),
from: z.string(),
subject: z.string(),
text: z.string(),
Expand Down

0 comments on commit c6f32eb

Please sign in to comment.