import { Prerequisites } from "docs-ui" export const metadata = { title: `Set Up React Email Templates for Cloud Projects`, } # {metadata.title} In this guide, you'll learn how to set up React Email templates for [sending emails in Cloud projects](../page.mdx). ## What is React Email? [React Email](https://react.email) is a library that allows you to create email templates using React components. You can then transform these templates into HTML strings for sending emails. React Email also allows you to preview and test your email templates during development. In this guide, you'll learn how to: - Install React Email dependencies in your Medusa project. - Create an invite user email template using React Email. - Preview email templates during development. - Send emails using the React Email template with Medusa Emails. You'll also find examples of common email templates built with React Email at the end of this guide. Medusa Emails is available for all Cloud organizations and projects, given you [don't have another Notification Module Provider for the `email` channel configured](../page.mdx#remove-other-email-notification-module-providers). You also optionally need to [verify your sending domain](../page.mdx#verify-email-sender-domain-on-cloud) to send emails to users outside your organization. --- ## Step 1: Install React Email Dependencies In the Medusa project where you want to set up email templates, install the following dependencies: ```bash npm2yarn npm install @react-email/components@0.3.3 @react-email/render@1.1.4 npm install -D @react-email/preview-server@4.2.5 react-email@4.2.5 ``` These packages include: - `@react-email/components`: Provides pre-built React components for building email templates. - `@react-email/render`: Renders React Email templates to HTML strings. - `@react-email/preview-server` and `react-email`: Development dependencies for previewing and testing email templates. Newer versions of React Email are not supported due to Node version incompatibilities on Cloud. --- ## Step 2: Create Invite User Email Template Next, create the `src/emails` directory to store your email templates in your Medusa project. Then, create your email templates as React components in that directory. For example, to create an email template for sending invites to new admin users, create the file `src/emails/invite-user.tsx` with the following content: ```tsx title="src/emails/invite-user.tsx" import { Text, Container, Heading, Html, Section, Tailwind, Head, Preview, Body, Button, } from "@react-email/components" type InviteEmailProps = { inviteUrl: string storeName: string } function Template({ inviteUrl, storeName }: InviteEmailProps) { return ( {`You've been invited to join ${storeName ?? ""}`} {/* Main Content */} You've been invited to join {storeName ?? ""} Click the button below to accept the invitation and get started.
{/* Footer */}
© {new Date().getFullYear()} {storeName}, Inc. All rights reserved.
) } export default function getInviteTemplate(props?: InviteEmailProps) { return (