Okay, hey guys,
I'm having a bit of an issue here. I'm using Vite, React, Node. What I'm trying to do:
- vercel receives form information after submit in backend
- stuff gets sanitized etc
- if okay send form values structured using my template with Resend
The issue is is that the template is a .tsx (because it uses react email components) file, which cannot be rendered by the backend. It's not found as template.js if I put it somewhere in the api dir. So I figured, well, Vite will render it if I put it in the root > lib/templates/formmailtemplate.tsx which should be shared?
api ├── config │ └── email.ts ├── contact.ts ├── controllers │ └── contactController.ts ├── middleware │ └── validation.ts ├── models │ └── Contact.ts ├── services │ └── emailService.ts └── utils ├── sanitization.ts └── spamDetection.ts lib └── ContactEmailTemplate.tsx
so I have
import ContactEmail from '../../lib/ContactEmailTemplate in api/services/mailservice.ts which should then send the email with this function:
const resendClient = initializeResend();
// RENDER REACT COMPONENT TO HTML. const emailHtml = await render( ContactEmail({ name: [contactData.name](https://contactdata.name), email: [contactData.email](https://contactdata.email), phone: [contactData.phone](https://contactdata.phone), message: contactData.message, submittedAt: formatSubmissionTime(), }));
// PREPARE EMAIL DATAconst emailData = { from: EMAIL_CONFIG.from, to: EMAIL_CONFIG.to, subject: EMAIL_CONFIG.subject([contactData.name](https://contactdata.name)), html: emailHtml};
// SEND EMAIL. const result = await resendClient.emails.send(emailData);However, Vercel is logging me this error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/lib/ContactEmail'
Is my path wrong or is it just my logic and is it impossible to use a react mail template in the backend? I'd really appreciate any help!