Skip to content

Commit f51817b

Browse files
author
Miriad
committed
feat: wire up Resend email service for sponsor pipeline
1 parent 05040fa commit f51817b

File tree

3 files changed

+84
-31
lines changed

3 files changed

+84
-31
lines changed

lib/sponsor/email-service.ts

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
/**
2-
* Email service for sponsor communications.
3-
*
4-
* STUBBED — needs RESEND_API_KEY
5-
* TODO: Wire up Resend when API key is available
6-
*/
1+
import { Resend } from 'resend'
72

8-
export interface EmailResult {
9-
success: boolean
10-
messageId?: string
11-
}
3+
const resend = new Resend(process.env.RESEND_API_KEY)
4+
5+
const FROM_EMAIL = 'Alex Patterson <alex@codingcat.dev>'
126

137
/**
14-
* Send an email to a sponsor contact.
15-
* Currently stubbed — logs the email and returns success.
8+
* Send a sponsor-related email via Resend.
9+
* Falls back to console logging if RESEND_API_KEY is not set.
1610
*/
1711
export async function sendSponsorEmail(
1812
to: string,
1913
subject: string,
2014
body: string
21-
): Promise<EmailResult> {
22-
// TODO: Wire up Resend when RESEND_API_KEY is available
23-
// import { Resend } from 'resend'
24-
// const resend = new Resend(process.env.RESEND_API_KEY)
25-
// const { data, error } = await resend.emails.send({
26-
// from: 'Alex Patterson <alex@codingcat.dev>',
27-
// to,
28-
// subject,
29-
// text: body,
30-
// })
15+
): Promise<{ success: boolean; messageId?: string }> {
16+
if (!process.env.RESEND_API_KEY) {
17+
console.warn('[SPONSOR] RESEND_API_KEY not set — logging email instead')
18+
console.log('[SPONSOR] Email:', { to, subject, body: body.slice(0, 200) + '...' })
19+
return { success: true }
20+
}
21+
22+
try {
23+
const { data, error } = await resend.emails.send({
24+
from: FROM_EMAIL,
25+
to: [to],
26+
subject,
27+
text: body,
28+
})
3129

32-
console.log('[SPONSOR] Email send (stubbed):', {
33-
to,
34-
subject,
35-
bodyLength: body.length,
36-
timestamp: new Date().toISOString(),
37-
})
30+
if (error) {
31+
console.error('[SPONSOR] Resend error:', error)
32+
return { success: false }
33+
}
3834

39-
return {
40-
success: true,
41-
messageId: `stub_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`,
35+
console.log('[SPONSOR] Email sent via Resend:', { to, subject, messageId: data?.id })
36+
return { success: true, messageId: data?.id }
37+
} catch (error) {
38+
console.error('[SPONSOR] Failed to send email:', error)
39+
return { success: false }
4240
}
4341
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"react-syntax-highlighter": "^15.6.6",
9797
"react-twitter-embed": "^4.0.4",
9898
"recharts": "2.15.4",
99+
"resend": "^6.9.3",
99100
"sanity": "^4.8.1",
100101
"sanity-plugin-cloudinary": "^1.4.0",
101102
"server-only": "^0.0.1",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)