So here’s what’s happening now.
I have a react frontend with react-email/components
installed. I have created a component called Email.jsx
and I’m trying to use this Component as the component for my E-mail. I know that the sending of email works because I have tested it with just plain html
. There’s a react
attribute in resend which would in theory allow me to use it. I have seen it work in videos, but I myself am running into issues. I will note that the frontend and express server are separate.
Here’s my email.jsx
import Logo from "../../public/images/logos/ecospring_logo_bordered.png";
import {
Html,
Button,
Tailwind,
Text,
Section,
Row,
Column,
Link,
Img,
} from "@react-email/components";
const Email = (otp) => {
return (
<>
<Html lang="en" dir="ltr">
<Tailwind>
<Section
// align="center"
// width="100%"
// border="0"
// cellPadding="0"
// cellSpacing="0"
// role="presentation"
className="text-text-1 text-center max-w-[360px] bg-background-color border border-card-background rounded-md shadow-md mt-20 mx-auto py-68 px-0 md:px-4 font-roboto"
>
<Row className="w-full">
<Column>
<Img
alt="ecospring_logo.png"
height="88"
src={Logo}
className="p-4 mx-auto"
width="212"
/>
<Text className="mt-16 font-semibold text-center uppercase text-text-1">
Verify Your Identity
</Text>
<Heading
as="h1"
className="mt-4 text-2xl font-medium text-center text-text-1"
>
Enter the following code to login.
</Heading>
<Section
// align="center"
// width="100%"
// border="0"
// cellPadding="0"
// cellSpacing="0"
// role="presentation"
className="bg-text-3 rounded-md mx-auto my-8 w-[280px]"
>
<Section>
<Row>
<Column>
<Text className="py-8 text-3xl font-bold text-center">
{otp.map((code) => {
<Text className="inline-block px-3 py-2 border border-white text-text-1">
{code}
</Text>;
})}
</Text>
</Column>
</Row>
</Section>
</Section>
<Text className="mx-4 leading-relaxed text-center text-text-1">
Not expecting this email?
</Text>
<Text className="p-4 mx-4 leading-relaxed text-center text-text-1">
Contact{" "}
<Link href="mailto:[email protected]" className="underline">
[email protected]
</Link>{" "}
if you did not request this code.
</Text>
</Column>
</Row>
</Section>
</Tailwind>
</Html>
</>
);
};
export default Email;
server.js
Express <- If I try to import it like below here, I get a cannot find module
error
import Email from "../pos_frontend/src/mail/Email";
server.js
<- Like this, I get TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".jsx"
import Email from "../pos_frontend/src/mail/Email.js";
I am sure that the path is correct, but I have no clue what I’m doing wrong.
server.js
<- Resend Part
app.post("/otp", (req, res) => {
try {
const payload = req.body;
resend.emails.send({
from: "[email protected]",
to: payload.email,
subject: "EcoSprings OTP Code",
html: `<p>PP Here IS OTP <strong>${payload.otp}</strong></p>`,
// react: Email(payload.otp),
});
res.send("email sent succesfully ");
} catch (error) {
console.error("Error sending email:", error);
res.status(500).send("Internal Server Error");
}
});
Like I have mentioned earlier, it works fine without the React Component