Email transaccional con plantillas React Email tipadas: Resend, SMTP o consola en desarrollo
Instalar
genpm add @core/emailQué obtienes
- Código en src/lib/email/, 9 archivos. (12,9 kB)
- Reglas de IA en src/lib/email/AGENTS.md, más archivos de reglas para tu IDE.
- Variables añadidas a .env.example: RESEND_API_KEY, EMAIL_FROM, APP_NAME.
README
@core/email
Transactional email with typed React Email templates: Resend, SMTP or console in dev
A GenPM module: source code + AI rules + MCP config, injected into your project instead of hidden in node_modules. The code lands in src/lib/email, pinned to a verified commit, and you own it.
Install
genpm add @core/emailNo genpm yet? curl -fsSL https://genpm.net/install.sh | sh (macOS/Linux), irm https://genpm.net/install.ps1 | iex (Windows), or one-off with npx @genpm-net/cli add @core/email.
Or let your AI agent do it: run genpm mcp setup once, then ask "add @core/email with genpm" in Claude Code, Cursor, VS Code, Windsurf, Codex or Gemini CLI. It shows you a dry-run plan before writing anything.
What it does
Transactional email with typed templates: sendEmail('welcome', { to, props }). Providers: Resend (default), SMTP
(optional, via nodemailer) and a console provider for development. Templates use React Email. No marketing lists,
no queues, no tracking pixels.
Setup
After genpm add, follow these steps (your AI agent finds the same steps in src/lib/email/AGENTS.md and can do them for you):
- Env:
EMAIL_FROM("App <hello@yourdomain.com>") andRESEND_API_KEY(verify the domain in Resend first). WithoutRESEND_API_KEY, outside production, emails are printed to the console. In production (next start) that fallback throws so mail is never lost silently; setEMAIL_PROVIDER=consoleto print them there too (local tests). OptionalAPP_NAME: brand name shown in the email layout (defaultApp).@types/reactis only needed at build time: move it to devDependencies if GenPM added it to dependencies. SMTP instead:EMAIL_PROVIDER=smtp,SMTP_URL=smtps://user:pass@host:465and installnodemailer. - Send from server code only:
import { sendEmail } from './lib/email/index.ts'; await sendEmail('welcome', { to: user.email, props: { name: user.name, appUrl: 'https://app.example.com' } }); - With
@core/auth(≥ 1.1.0): sendwelcomefrom itsonLoginhook whenisNewUseris true:app.route('/auth', authRoutes({ onLogin: ({ user, isNewUser }) => isNewUser && user.email ? sendEmail('welcome', { to: user.email, props: { name: user.name, appUrl: process.env.APP_URL ?? '' } }).then(() => undefined) : undefined, })); - Verify: run the app without
RESEND_API_KEYand check the console output.
What's inside
Paths are relative to src/lib/email.
index.ts— public API:sendEmail,renderEmail,setEmailProvider, provider factories,TemplateProps.send.ts— the template registry (templates) andsendEmail.templates/*.ts—welcome,magicLink,receipt, plus the sharedlayout.ts.providers.ts—EmailProviderinterface and implementations.
At a glance
- npm dependencies (proposed, never installed without asking):
resend,@react-email/components,@react-email/render,react,@types/react - Environment variables (added to
.env.example):RESEND_API_KEY,EMAIL_FROM,APP_NAME - AI rules:
AGENTS.md, loaded by your agent only when it works insrc/lib/email
Security
GenPM installs a 40-character commit SHA (never a branch), verifies an Ed25519-signed manifest, never runs install scripts and scans AI rules for prompt injection. Details: genpm.net/docs/security.
License
Esto es exactamente lo que lee tu IA cuando trabaja en src/lib/email. No se añade nada más a su contexto.
@core/email — rules for AI agents
Purpose
Transactional email with typed templates: sendEmail('welcome', { to, props }). Providers: Resend (default), SMTP
(optional, via nodemailer) and a console provider for development. Templates use React Email. No marketing lists,
no queues, no tracking pixels.
Map
index.ts— public API:sendEmail,renderEmail,setEmailProvider, provider factories,TemplateProps.send.ts— the template registry (templates) andsendEmail.templates/*.ts—welcome,magicLink,receipt, plus the sharedlayout.ts.providers.ts—EmailProviderinterface and implementations.
Integration
- Env:
EMAIL_FROM("App <hello@yourdomain.com>") andRESEND_API_KEY(verify the domain in Resend first). WithoutRESEND_API_KEY, outside production, emails are printed to the console. In production (next start) that fallback throws so mail is never lost silently; setEMAIL_PROVIDER=consoleto print them there too (local tests). OptionalAPP_NAME: brand name shown in the email layout (defaultApp).@types/reactis only needed at build time: move it to devDependencies if GenPM added it to dependencies. SMTP instead:EMAIL_PROVIDER=smtp,SMTP_URL=smtps://user:pass@host:465and installnodemailer. - Send from server code only:
import { sendEmail } from './lib/email/index.ts'; await sendEmail('welcome', { to: user.email, props: { name: user.name, appUrl: 'https://app.example.com' } }); - With
@core/auth(≥ 1.1.0): sendwelcomefrom itsonLoginhook whenisNewUseris true:app.route('/auth', authRoutes({ onLogin: ({ user, isNewUser }) => isNewUser && user.email ? sendEmail('welcome', { to: user.email, props: { name: user.name, appUrl: process.env.APP_URL ?? '' } }).then(() => undefined) : undefined, })); - Verify: run the app without
RESEND_API_KEYand check the console output.
Conventions
- New template: create
templates/<name>.tsexporting{ subject(props), render(props) }built withcreateElement as h(no JSX, so it works with anyjsxImportSource), then add it totemplatesandTemplatePropsinsend.ts. TypeScript then enforces its props everywhere. - Amounts in the currency minor unit (cents; whole yen for JPY; 3 decimals for KWD); links absolute (
https://…). - Keep
sendEmailcalls out of request hot paths when possible (after the response, or in a job).
Don't
- Don't send from the browser or expose
RESEND_API_KEYto client code. - Don't interpolate untrusted HTML into templates; pass plain strings (React escapes them).
- Don't log full email bodies in production (they may contain sign-in links).
# @core/email — rules for AI agents
## Purpose
Transactional email with typed templates: `sendEmail('welcome', { to, props })`. Providers: Resend (default), SMTP
(optional, via `nodemailer`) and a console provider for development. Templates use React Email. No marketing lists,
no queues, no tracking pixels.
## Map
- `index.ts` — public API: `sendEmail`, `renderEmail`, `setEmailProvider`, provider factories, `TemplateProps`.
- `send.ts` — the template registry (`templates`) and `sendEmail`.
- `templates/*.ts` — `welcome`, `magicLink`, `receipt`, plus the shared `layout.ts`.
- `providers.ts` — `EmailProvider` interface and implementations.
## Integration
1. Env: `EMAIL_FROM` (`"App <hello@yourdomain.com>"`) and `RESEND_API_KEY` (verify the domain in Resend first).
Without `RESEND_API_KEY`, outside production, emails are printed to the console. In production (`next start`) that
fallback throws so mail is never lost silently; set `EMAIL_PROVIDER=console` to print them there too (local tests).
Optional `APP_NAME`: brand name shown in the email layout (default `App`).
`@types/react` is only needed at build time: move it to devDependencies if GenPM added it to dependencies.
SMTP instead: `EMAIL_PROVIDER=smtp`, `SMTP_URL=smtps://user:pass@host:465` and install `nodemailer`.
2. Send from server code only:
```ts
import { sendEmail } from './lib/email/index.ts';
await sendEmail('welcome', { to: user.email, props: { name: user.name, appUrl: 'https://app.example.com' } });
```
3. With `@core/auth` (≥ 1.1.0): send `welcome` from its `onLogin` hook when `isNewUser` is true:
```ts
app.route('/auth', authRoutes({
onLogin: ({ user, isNewUser }) =>
isNewUser && user.email ? sendEmail('welcome', { to: user.email, props: { name: user.name, appUrl: process.env.APP_URL ?? '' } }).then(() => undefined) : undefined,
}));
```
4. Verify: run the app without `RESEND_API_KEY` and check the console output.
## Conventions
- New template: create `templates/<name>.ts` exporting `{ subject(props), render(props) }` built with
`createElement as h` (no JSX, so it works with any `jsxImportSource`), then add it to `templates` and
`TemplateProps` in `send.ts`. TypeScript then enforces its props everywhere.
- Amounts in the currency minor unit (cents; whole yen for JPY; 3 decimals for KWD); links absolute (`https://…`).
- Keep `sendEmail` calls out of request hot paths when possible (after the response, or in a job).
## Don't
- Don't send from the browser or expose `RESEND_API_KEY` to client code.
- Don't interpolate untrusted HTML into templates; pass plain strings (React escapes them).
- Don't log full email bodies in production (they may contain sign-in links).
El árbol exacto que se inyectará, tras aplicar .genpmignore. Anclado a
// Layout común de los correos (React Email sin JSX: funciona aunque el proyecto use otro jsxImportSource).
import { Body, Container, Head, Hr, Html, Preview, Section, Text } from '@react-email/components';
import { createElement as h, type ReactNode } from 'react';
export const brand = { name: process.env.APP_NAME ?? 'App', color: '#0B0D11' };
const body = { backgroundColor: '#f6f7f9', fontFamily: 'Helvetica, Arial, sans-serif', padding: '24px 0' };
const card = { backgroundColor: '#ffffff', borderRadius: '8px', padding: '32px', maxWidth: '520px' };
export const text = { fontSize: '15px', lineHeight: '24px', color: '#0B0D11' };
export const muted = { fontSize: '13px', color: '#6A7180' };
export const button = {
backgroundColor: brand.color,
color: '#ffffff',
padding: '12px 20px',
borderRadius: '6px',
fontWeight: 600,
textDecoration: 'none',
};
export function Layout(props: { preview: string; children?: ReactNode }) {
return h(
Html,
{ lang: 'en' },
h(Head),
h(Preview, null, props.preview),
h(
Body,
{ style: body },
h(
Container,
{ style: card },
h(Section, null, props.children),
h(Hr),
h(Text, { style: muted }, brand.name),
),
),
);
}
Este paquete no declara servidores MCP.
- genpm
- ninguno
- npm
- @react-email/components ^1.0.12@react-email/render ^2.1.0@types/react ^19.0.0react ^19.0.0resend ^6.32.0
- propuesta
- GenPM propone el comando npm y solo lo ejecuta si dices que sí.
- escaneo
- escaneo superado · 0 hallazgos
- commit
- v1.0.4 → cbc155965170820a92134ecf8b4b32411a629f5d · verificado tras la descarga
- scripts
- Ninguno. GenPM nunca ejecuta código del paquete.
- licencia
- MIT
- Calidad
- 100/100
- Licencia reconocidacumplido
- AGENTS.md explica su propósitocumplido
- AGENTS.md tiene pasos de integracióncumplido
- AGENTS.md lista convenciones o prohibicionescumplido
- Incluye testscumplido
- Escaneo de seguridad superadocumplido
- Publicado en los últimos 6 mesescumplido
- Publicador verificadocumplido
- Resumen y palabras clavecumplido
- reporte
- ¿Ves algo raro?