32 lines
727 B
TypeScript
32 lines
727 B
TypeScript
|
|
const RESEND_API_KEY = process.env.RESEND_API_KEY!;
|
||
|
|
const RESEND_FROM_EMAIL = process.env.RESEND_FROM_EMAIL!;
|
||
|
|
|
||
|
|
interface SendEmailOptions {
|
||
|
|
to: string;
|
||
|
|
subject: string;
|
||
|
|
html: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function sendEmail({ to, subject, html }: SendEmailOptions) {
|
||
|
|
const response = await fetch('https://api.resend.com/emails', {
|
||
|
|
method: 'POST',
|
||
|
|
headers: {
|
||
|
|
Authorization: `Bearer ${RESEND_API_KEY}`,
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
},
|
||
|
|
body: JSON.stringify({
|
||
|
|
from: RESEND_FROM_EMAIL,
|
||
|
|
to,
|
||
|
|
subject,
|
||
|
|
html,
|
||
|
|
}),
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
const error = await response.text();
|
||
|
|
throw new Error(`Failed to send email: ${error}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.json();
|
||
|
|
}
|