当前位置: 首页 > Skill >

Resend Skills

Resend Skills

Resend Skills

用于在使用 Resend 邮件 API 时——发送事务邮件(单发或批量),通过 webhook 接收入站邮件,管理邮件模板,...

3.3.3 2026.11.22 830
获取Skill文件查看使用说明
作 者:陆言 许可证: 更新时间:2026.11.22
本文目录展开

Resend

Quick Send — Node.js

import { Resend } from 'resend';

const resend = new Resend(process.env.RESEND_API_KEY);

const { data, error } = await resend.emails.send(
  {
    from: 'Acme <onboarding@resend.dev>',
    to: ['delivered@resend.dev'],
    subject: 'Hello World',
    html: '<p>Email body here</p>',
  },
  { idempotencyKey: `welcome-email/${userId}` }
);

if (error) {
  console.error('Failed:', error.message);
  return;
}
console.log('Sent:', data.id);

Key gotcha: The Resend Node.js SDK does NOT throw exceptions — it returns { data, error }. Always check error explicitly instead of using try/catch for API errors.

Quick Send — Python

import resend
import os

resend.api_key = os.environ["RESEND_API_KEY"]

email = resend.Emails.send({
    "from": "Acme <onboarding@resend.dev>",
    "to": ["delivered@resend.dev"],
    "subject": "Hello World",
    "html": "<p>Email body here</p>",
}, idempotency_key=f"welcome-email/{user_id}")

Single vs Batch Decision

Choose When
Single (POST /emails) 1 email, needs attachments, needs scheduling
Batch (POST /emails/batch) 2-100 distinct emails, no attachments, no scheduling

Batch is atomic — if one email fails validation, the entire batch fails. Always validate before sending. Batch does NOT support attachments or scheduled_at.

Idempotency Keys (Critical for Retries)

Prevent duplicate emails when retrying failed requests:

Key Facts
Format (single) <event-type>/<entity-id> (e.g., welcome-email/user-123)
Format (batch) batch-<event-type>/<batch-id> (e.g., batch-orders/batch-456)
Expiration 24 hours
Max length 256 characters
Same key + same payload Returns original response without resending
Same key + different payload Returns 409 error

Quick Receive (Node.js)

import { Resend } from 'resend';

const resend = new Resend(process.env.RESEND_API_KEY);

export async function POST(req: Request) {
  const payload = await req.text(); // Must use raw text, not req.json()

  const event = resend.webhooks.verify({
    payload,
    headers: {
      'svix-id': req.headers.get('svix-id'),
      'svix-timestamp': req.headers.get('svix-timestamp'),
      'svix-signature': req.headers.get('svix-signature'),
    },
    secret: process.env.RESEND_WEBHOOK_SECRET,
  });

  if (event.type === 'email.received') {
    // Webhook has metadata only — call API for body
    const { data: email } = await resend.emails.receiving.get(
      event.data.email_id
    );
    console.log(email.text);
  }

  return new Response('OK', { status: 200 });
}

Key gotcha: Webhook payloads do NOT contain the email body. You must call resend.emails.receiving.get() separately.

What Do You Need?

Task Reference
Send a single email sending/overview.md — parameters, deliverability, testing
Send batch emails sending/overview.md → sending/batch-email-examples.md
Full SDK examples (Node.js, Python, Go, cURL) sending/single-email-examples.md
Idempotency, retries, error handling sending/best-practices.md
Get, list, reschedule, cancel emails sending/email-management.md
Receive inbound emails receiving.md — domain setup, webhooks, attachments
Manage templates (CRUD, variables) templates.md — lifecycle, aliases, pagination
Set up webhooks (events, verification) webhooks.md — verification, CRUD, retry schedule, IP allowlist
Manage domains (create, verify, DNS) domains.md — regions, TLS, tracking, capabilities
Manage contacts (CRUD, properties) contacts.md — segments, topics, custom properties
Send broadcasts (marketing campaigns) broadcasts.md — lifecycle, scheduling, template variables
Manage API keys api-keys.md — permission scoping, domain restrictions
View API request logs logs.md — list and retrieve API call history, debugging
Define contact properties contact-properties.md — custom fields for contacts
Manage segments (contact groups) segments.md — broadcast targeting, contact grouping
Manage topics (subscriptions) topics.md — opt-in/out preferences, broadcast filtering
Create automations (event-driven workflows) automations.md — steps, connections, runs, conditions
Define and send events (automation triggers) events.md — schemas, payloads, contact association
Install SDK (8+ languages) installation.md
Set up an AI agent inbox Install the agent-email-inbox skill — covers security levels for untrusted input

SDK Version Requirements

Always install the latest SDK version. These are the minimum versions for full functionality (sending, receiving, webhook verification):

Language Package Min Version Install
Node.js resend >= 6.9.2 npm install resend
Python resend >= 2.21.0 pip install resend
Go resend-go/v3 >= 3.1.0 go get github.com/resend/resend-go/v3
Ruby resend >= 1.0.0 gem install resend
PHP resend/resend-php >= 1.1.0 composer require resend/resend-php
Rust resend-rs >= 0.20.0 cargo add resend-rs
Java resend-java >= 4.11.0 See installation.md
.NET Resend >= 0.2.1 dotnet add package Resend

If the project already has a Resend SDK installed, check the version and upgrade if it's below the minimum. Older SDKs may be missing webhooks.verify() or emails.receiving.get().

See installation.md for full installation commands, language detection, and cURL fallback.

Common Setup

API Key

Store in environment variable — never hardcode:

export RESEND_API_KEY=re_xxxxxxxxx

Get your key at resend.com/api-keys.

Detect Project Language

Check for these files: package.json (Node.js), requirements.txt/pyproject.toml (Python), go.mod (Go), Gemfile (Ruby), composer.json (PHP), Cargo.toml (Rust), pom.xml/build.gradle (Java), *.csproj (.NET).

Common Mistakes

# Mistake Fix
1 Retrying without idempotency key Always include idempotency key — prevents duplicate sends on retry. Format: <event-type>/<entity-id>
2 Not verifying webhook signatures Always verify with resend.webhooks.verify() — unverified events can't be trusted
3 Template variable name mismatch Variable names are case-sensitive — must match the template definition exactly. Use triple mustache {{{VAR}}} syntax
4 Expecting email body in webhook payload Webhooks contain metadata only — call resend.emails.receiving.get() for body content
5 Using try/catch for Node.js SDK errors SDK returns { data, error } — check error explicitly, don't wrap in try/catch
6 Using batch for emails with attachments Batch doesn't support attachments — use single sends instead
7 Testing with fake emails (test@gmail.com) Use delivered@resend.dev — fake addresses bounce and hurt reputation
8 Sending with draft template Templates must be published before sending — call .publish() first
9 html + template in same send call Mutually exclusive — remove html/text/react when using template
10 MX record not lowest priority for inbound Ensure Resend's MX has the lowest number (highest priority) or emails won't route
11 403 when sending from resend.dev The default onboarding@resend.dev is a sandbox — it can only deliver to your Resend account email. Verify your own domain first
12 403 domain mismatch The from address domain must exactly match a verified domain. Verified send.acme.com but sending from user@acme.com will fail
13 Calling Resend API from the browser (CORS) The API does not support CORS — this is intentional to protect your API key. Always call from server-side (API routes, serverless functions)
14 401 restricted_api_key A sending-only API key was used on a non-sending endpoint (domains, contacts, etc.). Create a full-access key instead

Cross-Cutting Concerns

Send + Receive Together

Auto-replies, email forwarding, or any receive-then-send workflow requires both capabilities:

  1. Set up inbound domain first (see receiving.md)
  2. Set up sending (see sending/overview.md)
  3. Note: batch sending does NOT support attachments or scheduling — use single sends when forwarding with attachments

AI Agent Inbox

If your system processes untrusted email content and takes actions (refunds, database changes, forwarding), install the agent-email-inbox skill. This applies whether or not AI is involved — any system interpreting freeform email content from external senders needs security measures.

Marketing Emails

The sending capabilities in this skill are for transactional email (receipts, confirmations, notifications). For marketing campaigns to large subscriber lists with unsubscribe links and engagement tracking, use Resend Broadcasts — see broadcasts.md for the API.

Domain Warm-up

New domains must gradually increase sending volume. Day 1 limit: ~150 emails (new domain) or ~1,000 (existing domain). See the warm-up schedule in sending/overview.md.

Testing

Never test with fake addresses at real email providers (test@gmail.com, fake@outlook.com) — they bounce and destroy sender reputation.

Address Result
delivered@resend.dev Simulates successful delivery
bounced@resend.dev Simulates hard bounce
complained@resend.dev Simulates spam complaint

Suppression List

Resend automatically suppresses hard-bounced and spam-complained addresses. Sending to suppressed addresses fires the email.suppressed webhook event instead of attempting delivery. Manage in Dashboard → Suppressions.

Webhook Event Types

Event Trigger
email.sent API request successful
email.delivered Reached recipient's mail server
email.bounced Permanently rejected (hard bounce)
email.complained Recipient marked as spam
email.opened / email.clicked Recipient engagement
email.delivery_delayed Soft bounce, Resend retries
email.received Inbound email arrived
domain.* / contact.* Domain/contact changes

See webhooks.md for full details, signature verification, and retry schedule.

Error Handling Quick Reference

Code Action
400, 422 Fix request parameters, don't retry
401 Check API key — restricted_api_key means sending-only key used on non-sending endpoint
403 Verify domain ownership — common causes: resend.dev sandbox, from domain mismatch, unverified domain
409 Idempotency conflict — use new key or fix payload
429 Rate limited — retry with exponential backoff (default rate limit: 2 req/s)
500 Server error — retry with exponential backoff

Resources

  • Resend Documentation
  • API Reference
  • Dashboard

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,019
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,014
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,014
Skill 文件
  • SKILL.md
    • Resend
    • Quick Send — Node.js
    • Quick Send — Python
      • Single vs Batch Decision
      • Idempotency Keys (Critical for Retries)
    • Quick Receive (Node.js)
    • What Do You Need?
    • SDK Version Requirements
    • Common Setup
      • API Key
      • Detect Project Language
    • Common Mistakes
    • Cross-Cutting Concerns
      • Send + Receive Together
      • AI Agent Inbox
      • Marketing Emails
      • Domain Warm-up
      • Testing
      • Suppression List
      • Webhook Event Types
    • Error Handling Quick Reference
    • Resources
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期