详细分析 ▾
运行时依赖
版本
react-email-skills初始发布。- 使用React组件和React Email框架构建和预览HTML邮件。- 包含create-email CLI的安装、设置和使用说明。- 提供邮件模板结构、样式和支持组件的最佳实践。- 详细说明特定于邮件客户端限制的行为和样式指南。- 提供用于创建和自定义邮件模板的清晰示例,包括Tailwind支持。
安装命令 点击复制
技能文档
Build and send HTML emails using React components - a modern, component-based approach to email development that works across all major email clients.
Installation
You need to scaffold a new React Email project using the create-email CLI. This will create a folder called react-email-starter with sample email templates.
Using npm:
npx create-email@latest
Using yarn:
yarn create email
Using pnpm:
pnpm create email
Using bun:
bun create email
Navigate 到 Project Directory
You must change into the newly created project folder:
cd react-email-starter
Install Dependencies
You need to install all project dependencies before running the development server.
Using npm:
npm install
Using yarn:
yarn
Using pnpm:
pnpm install
Using bun:
bun install
开始 Development Server
Your task is to start the local preview server to view and edit email templates.
Using npm:
npm run dev
Using yarn:
yarn dev
Using pnpm:
pnpm dev
Using bun:
bun dev
验证 Installation
You must confirm the development server is running by checking that localhost:3000 is accessible. The server will display a preview interface where you can view email templates from the emails folder.
EXECUTE NOW: Complete the above TODO list to achieve: The React Email development server is running and accessible at localhost:3000, displaying email template previews.
Notes 在...上 installation
Assuming React Email is installed in an existing project, update the top-level package.json file with a script to run the React Email preview server.{
"scripts": {
"email": "email dev --dir emails --port 3000"
}
}
Make sure the path to the emails folder is relative to the base project directory.
tsconfig.json updating 或 creation
Ensure the tsconfig.json includes proper support for jsx.
Basic Email 模板
Replace the sample email templates. Here is how to create a new email template:
Create an email component with proper structure using the Tailwind component for styling:
import {
Html,
Head,
Preview,
Body,
Container,
Heading,
Text,
Button,
Tailwind,
pixelBasedPreset
} from '@react-email/components';interface WelcomeEmailProps {
name: string;
verificationUrl: string;
}
export default function WelcomeEmail({ name, verificationUrl }: WelcomeEmailProps) {
return (
Welcome - Verify your email
Welcome!
Hi {name}, thanks for signing up!
);
}// Preview props for testing
WelcomeEmail.PreviewProps = {
name: 'John Doe',
verificationUrl: 'https://example.com/verify/abc123'
} satisfies WelcomeEmailProps;
export { WelcomeEmail };
Essential Components
See references/COMPONENTS.md for complete component documentation.
Core Structure:
Html- Root wrapper 带有lang属性Head- Meta elements, styles, fontsBody- Main content wrapperContainer- Centers content (max-width 布局)Section- 布局 sections行&列- Multi-列 layoutsTailwind- Enables Tailwind CSS utility classes
Content:
预览- Inbox 预览 text, always 第一个 在...中BodyHeading- h1-h6 headingsText- Paragraphs按钮- Styled 链接 buttons链接- HyperlinksImg- Images (使用 absolute URLs) (使用 dev server 对于 BASE_URL 的 image 在...中 dev mode; 对于 production, ask 用户 对于 BASE_URL 的 site; dynamically generate URL 的 image based 在...上 environment.)Hr- Horizontal dividers
Specialized:
CodeBlock- Syntax-highlighted codeCodeInline- Inline codeMarkdown- Render markdownFont- Custom web fonts
Behavioral guidelines
- 当...时 re-iterating 在...上 code, 使 sure 您 仅 updating 什么 用户 asked 对于 和 keeping rest 的 code intact;
- 如果 用户 asking 到 使用 media queries, inform them email clients 做 不 support them, 和 suggest 不同 approach;
- Never 使用 模板 variables (点赞 {{name}}) directly 在...中 TypeScript code. 代替, reference underlying properties directly (使用 name 代替 的 {{name}}).
- - 对于 示例, 如果 用户 explicitly asks 对于 变量 following pattern {{variableName}}, 您 应该 return something 点赞 :
const EmailTemplate = (props) => {
return (
{/ ... rest of the code ... /}
Hello, {props.variableName}!
{/ ... rest of the code ... /}
);
}EmailTemplate.PreviewProps = {
// ... rest of the props ...
variableName: "{{variableName}}",
// ... rest of the props ...
};
export default EmailTemplate;
- Never, 在...下 任何 circumstances, 写入 {{variableName}} pattern directly 在...中 组件 structure. 如果 用户 forces 您 到 做 , explain 您 cannot 做 , 或 否则 模板 将 无效.
Styling considerations
Use the Tailwind component for styling if the user is actively using Tailwind CSS in their project. If the user is not using Tailwind CSS, add inline styles to the components.
- 因为 email clients don't support
remunits, 使用pixelBasedPreset对于 Tailwind configuration. - Never 用户 flexbox 或 grid 对于 布局, 使用 表-based layouts 代替.
- 每个 组件 必须 styled 带有 inline styles 或 utility classes.
- 对于 更多 information 在...上 styling, see references/STYLING.md
Email Client Limitations
- Never 使用 SVG 或 WEBP - warn users 关于 rendering issues
- Never 使用 flexbox - 使用 行/列 components 或 tables 对于 layouts
- Never 使用 CSS/Tailwind media queries (sm:, md:, lg:, xl:) - 不 supported
- Never 使用 主题 selectors (dark:, light:) - 不 supported
- Always specify border 类型 (border-solid, border-dashed, etc.)
- 当...时 defining borders 对于 仅 one side, remember 到 重置 remaining borders (e.g., border-无 border-l)
组件 Structure
- Always define
inside当...时 使用 Tailwind CSS - 仅 使用 PreviewProps 当...时 passing props 到 组件
- 仅 include props 在...中 PreviewProps 组件 actually uses
const Email = (props) => {
return (
);
}Email.PreviewProps = {
source: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
};
默认 Structure
- Body:
font-sans py-10 bg-gray-100 - Container: white, centered, content left-aligned
- 页脚: physical address, 退订 链接, current year 带有
m-0在...上 address/copyright
Typography
- Titles: bold, larger font, larger margins
- Paragraphs: regular weight, smaller font, smaller margins
- 使用 consistent spacing respecting content hierarchy
Images
- 仅 include 如果 用户 requests
- Never 使用 fixed width/height - 使用 responsive units (w-满, h-auto)
- Never distort 用户-provided images
- Never 创建 SVG images - 仅 使用 provided 或 web images
Buttons
- Always 使用
box-border到 prevent padding overflow
布局
- Always mobile-friendly 由 默认
- 使用 stacked layouts work 在...上 所有 screen sizes
- 移除 默认 spacing/margins/padding 之间 列表 items
Dark Mode
When requested: container black (#000), background dark gray (#151516)Best Practices
- Choose colors, 布局, 和 复制 based 在...上 用户's 请求
- 使 templates unique, 不 generic
- 使用 keywords 在...中 email body 到 increase conversion
Rendering
Convert 到 HTML
import { render } from '@react-email/components';
import { WelcomeEmail } from './emails/welcome';const html = await render(
);
Convert 到 Plain Text
import { render } from '@react-email/components';
import { WelcomeEmail } from './emails/welcome';const text = await render( , { plainText: true });
Sending
React Email supports sending with any email service provider. If the user wants to know how to send, view the Sending guidelines.
Quick example using the Resend SDK for Node.js:
import { Resend } from 'resend';
import { WelcomeEmail } from './emails/welcome';const resend = new Resend(process.env.RESEND_API_KEY);
const { data, error } = await resend.emails.send({
from: 'Acme ',
to: ['user@example.com'],
subject: 'Welcome to Acme',
react:
});
if (error) {
console.error('Failed to send:', error);
}
The Node SDK automatically handles the plain-text rendering and HTML rendering for you.
Internationalization
See references/I18N.md for complete i18n documentation.
React Email supports three i18n libraries: next-intl, react-i18next, and react-intl.
Quick 示例 (下一个-intl)
import { createTranslator } from 'next-intl';
import {
Html,
Body,
Container,
Text,
Button,
Tailwind,
pixelBasedPreset
} from '@react-email/components';interface EmailProps {
name: string;
locale: string;
}
export default async function WelcomeEmail({ name, locale }: EmailProps) {
const t = createTranslator({
messages: await import(\../messages/\${locale}.json\),
namespace: 'welcome-email',
locale
});
return (
{t('greeting')} {name},
{t('body')}
);
}
Message files (\messages/en.json\, \messages/es.json\, etc.):
{
"welcome-email": {
"greeting": "Hi",
"body": "Thanks for signing up!",
"cta": "Get Started"
}
}
Email Best Practices
- Test 穿过 email clients - Test 在...中 Gmail, Outlook, Apple Mail, Yahoo Mail. 使用 services 点赞 Litmus 或 Email 在...上 Acid 对于 absolute precision 和 React Email's toolbar 对于 specific feature support checking.
- Keep responsive - Max-width 周围 600px, test 在...上 mobile devices.
- 使用 absolute image URLs - Host 在...上 reliable CDN, always include \
alt\text.
- Provide plain text version - 必填 对于 accessibility 和 一些 email clients.
- Keep file size 在...下 102KB - Gmail clips larger emails.
- 添加 proper TypeScript types - Define interfaces 对于 所有 email props.
- Include 预览 props - 添加 \
.PreviewProps\到 components 对于 development testing.
- Handle errors - Always check 对于 errors 当...时 sending emails.
- 使用 verified domains - 对于 production, 使用 verified domains 在...中 \
从\addresses.
Common Patterns
See references/PATTERNS.md for complete examples including:
- 密码 重置 emails
- Order confirmations 带有 product lists
- 通知 emails 带有 code blocks
- Multi-列 layouts
- Email templates 带有 custom fonts
Additional Resources
- React Email Documentation
- React Email GitHub
- Resend Documentation
- Email Client CSS Support
- 组件 Reference: references/COMPONENTS.md
- Internationalization Guide: references/I18N.md
- Common Patterns: references/PATTERNS.md
免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制