Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

sendgrid

БесплатноБез исполняемых скриптовНе проверен

SendGrid (by Twilio) sends transactional and marketing email through an HTTP API or SMTP. Use when a user asks to send emails programmatically, set up…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

SendGrid

Overview

SendGrid delivers email at scale through the v3 Mail Send API (POST https://api.sendgrid.com/v3/mail/send) or SMTP. This skill covers sending with @sendgrid/mail (8.1.x), dynamic templates, bulk sends with personalizations, the signed Event Webhook, and domain authentication. API reference: https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send.

Instructions

Step 1: Setup

Create an API key with the "Mail Send" permission only (Settings, API Keys) and keep it in an environment variable. The from address must belong to an authenticated domain or a verified single sender, otherwise the API returns 403.

npm install @sendgrid/mail          # Python: pip install sendgrid
export SENDGRID_API_KEY="SG.xxxxxxxx"   # set in your secret manager, never commit it
// lib/email.ts
import sgMail from '@sendgrid/mail'

sgMail.setApiKey(process.env.SENDGRID_API_KEY!)
export { sgMail }

Step 2: Send a single email

import { sgMail } from './lib/email'

await sgMail.send({
  to: '[email protected]',
  from: { email: '[email protected]', name: 'Northwind Logistics' },
  subject: 'Welcome to Northwind',
  text: 'Thanks for signing up!',
  html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
})

// Dynamic template: subject and body live in the template (IDs start with "d-")
await sgMail.send({
  to: '[email protected]',
  from: { email: '[email protected]', name: 'Northwind Logistics' },
  templateId: 'd-2f9a1c0b7e4d4c5a8b3e6d1f0a9b8c7d',
  dynamicTemplateData: { name: 'Maria', action_url: 'https://app.northwind-logistics.com/verify?token=8f3a' },
})

send resolves with [response, body]; a 202 means accepted for processing, not delivered. Failures throw an error whose response.body.errors lists the reasons.

To test without delivering, add mailSettings: { sandboxMode: { enable: true } }; the API validates the request and returns 200.

Step 3: Bulk sending

Pick the right method:

  • sgMail.sendMultiple({ to: [a, b, c], ... }) sends one separate email per recipient (recipients do not see each other), same content, one API request.
  • sgMail.send({ to: [a, b, c], ... }) puts all addresses in one visible "to" list. Do not use it for bulk mail.
  • sgMail.send([msg1, msg2, ...]) sends the messages in parallel as separate API requests, one request per message. Avoid it for thousands of recipients: it can hit rate limits.
  • For different data per recipient in one request, use personalizations (the API accepts up to 1000 per request):
const customers = [
  { email: '[email protected]', name: 'Maria', plan: 'Pro', usage: 8120 },
  { email: '[email protected]', name: 'James', plan: 'Team', usage: 2310 },
]

for (let i = 0; i < customers.length; i += 1000) {
  await sgMail.send({
    from: { email: '[email protected]', name: 'Northwind Billing' },
    templateId: 'd-2f9a1c0b7e4d4c5a8b3e6d1f0a9b8c7d',
    personalizations: customers.slice(i, i + 1000).map((c) => ({
      to: [{ email: c.email }],
      dynamicTemplateData: { name: c.name, plan: c.plan, usage: c.usage },
    })),
  })
}

Each personalization is delivered as its own email. For scheduled sends use sendAt (unix seconds, up to 72 hours ahead).

Step 4: Event Webhook with signature verification

Enable the Event Webhook in Settings, Mail Settings, Event Webhook, choose events (processed, delivered, deferred, bounce, dropped, open, click, spamreport, unsubscribe, group_unsubscribe, group_resubscribe) and turn on Signed Event Webhook Requests to get a public key. SendGrid posts a JSON array of events, signed with ECDSA in the headers X-Twilio-Email-Event-Webhook-Signature and X-Twilio-Email-Event-Webhook-Timestamp. Verify against the raw request bytes; parsing and re-serializing the JSON breaks the signature.

npm install @sendgrid/eventwebhook
// app/api/webhooks/sendgrid/route.ts (Next.js App Router)
import { NextRequest, NextResponse } from 'next/server'
import { EventWebhook, EventWebhookHeader } from '@sendgrid/eventwebhook'

export async function POST(req: NextRequest) {
  const raw = await req.text()
  const signature = req.headers.get(EventWebhookHeader.SIGNATURE())!
  const timestamp = req.headers.get(EventWebhookHeader.TIMESTAMP())!

  const verifier = new EventWebhook()
  const key = verifier.convertPublicKeyToECDSA(process.env.SENDGRID_WEBHOOK_PUBLIC_KEY!)
  if (!verifier.verifySignature(key, raw, signature, timestamp)) {
    return NextResponse.json({ error: 'bad signature' }, { status: 403 })
  }

  for (const e of JSON.parse(raw) as Array<{ email: string; event: string; sg_message_id: string }>) {
    if (e.event === 'bounce' || e.event === 'dropped') await markUndeliverable(e.email)
    if (e.event === 'spamreport' || e.event === 'unsubscribe') await optOut(e.email)
  }
  return N
Полный SKILL.md на GitHub

Установить sendgrid в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл sendgrid?

SendGrid (by Twilio) sends transactional and marketing email through an HTTP API or SMTP. Use when a user asks to send emails programmatically, set up transactional email delivery, send bulk email with dynamic templates, verify Event Webhook signatures, track opens, clicks and bounces, handle unsubscribes, or set up SPF and DKIM domain authentication. Covers the @sendgrid/mail Node.js client, personalizations for bulk sends, sandbox mode and deliverability setup.

Как установить скилл sendgrid?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл sendgrid запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить sendgrid с