11import { Resend } from 'resend'
2+ import { createLogger } from '@/lib/logs/console-logger'
23
34interface EmailOptions {
45 to : string
@@ -13,8 +14,13 @@ interface SendEmailResult {
1314 data ?: any
1415}
1516
16- // Initialize Resend with API key
17- const resend = new Resend ( process . env . RESEND_API_KEY )
17+ const logger = createLogger ( 'Mailer' )
18+
19+ const resendApiKey = process . env . RESEND_API_KEY
20+ const resend =
21+ resendApiKey && resendApiKey !== 'placeholder' && resendApiKey . trim ( ) !== ''
22+ ? new Resend ( resendApiKey )
23+ : null
1824
1925export async function sendEmail ( {
2026 to,
@@ -25,6 +31,19 @@ export async function sendEmail({
2531 try {
2632 const senderEmail = from || 'noreply@simstudio.ai'
2733
34+ if ( ! resend ) {
35+ logger . info ( 'Email not sent (Resend not configured):' , {
36+ to,
37+ subject,
38+ from : senderEmail ,
39+ } )
40+ return {
41+ success : true ,
42+ message : 'Email logging successful (Resend not configured)' ,
43+ data : { id : 'mock-email-id' } ,
44+ }
45+ }
46+
2847 const { data, error } = await resend . emails . send ( {
2948 from : `Sim Studio <${ senderEmail } >` ,
3049 to,
@@ -33,7 +52,7 @@ export async function sendEmail({
3352 } )
3453
3554 if ( error ) {
36- console . error ( 'Resend API error:' , error )
55+ logger . error ( 'Resend API error:' , error )
3756 return {
3857 success : false ,
3958 message : error . message || 'Failed to send email' ,
@@ -46,7 +65,7 @@ export async function sendEmail({
4665 data,
4766 }
4867 } catch ( error ) {
49- console . error ( 'Error sending email:' , error )
68+ logger . error ( 'Error sending email:' , error )
5069 return {
5170 success : false ,
5271 message : 'Failed to send email' ,
0 commit comments