用途:本技能用于配置 SendGrid 账户以进行邮件发送。SendGrid 是 Twilio 的邮件发送引擎,但使用独立认证体系:SendGrid API Key 以 SG. 开头,与 Twilio API Key 不同,不能用 Account SID/Auth Token 访问 SendGrid,也没有 Twilio MCP 工具封装 SendGrid。
主要能力与用法:在 SendGrid Console 的 Settings > API Keys 获取密钥,设置环境变量 export SENDGRID_API_KEY=SG.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx。SDK 安装:Python 用 pip install sendgrid;Node.js 用 npm install @sendgrid/mail;Java 用 Maven 依赖 com.sendgrid:sendgrid-java;C# 用 dotnet add package SendGrid;Ruby 用 gem install sendgrid-ruby;PHP 用 composer require sendgrid/sendgrid;Go 用 go get github.com/sendgrid/sendgrid-go。
API Key 权限:Full Access 仅限开发,切勿用于生产;生产应使用 Restricted Access 并只授予所需范围(如仅 Mail Send);Billing Access 用于账户管理。仅 Mail Send 的密钥无法读取退订、管理模板或访问统计,遇到 403 Forbidden 应检查权限。
SMTP 中继:服务器 smtp.sendgrid.net,端口 587(TLS)或 465(SSL),用户名固定为 apikey,密码为 SendGrid API Key。
域名认证:Single Sender Verification 仅用于测试,生产需域名认证。在 Console 的 Settings > Sender Authentication > Authenticate Your Domain 创建 3 条 CNAME 记录:s1._domainkey.yourdomain.com → s1.domainkey.u1234.wl.sendgrid.net(DKIM)、s2._domainkey.yourdomain.com → s2.domainkey.u1234.wl.sendgrid.net(DKIM)、em1234.yourdomain.com → u1234.wl.sendgrid.net(return path)。可通过 GET /v3/whitelabel/domains/{id}/validate 验证。之后配置 _dmarc.yourdomain.com 的 DMARC 记录,建议先用 p=none 监控。专用 IP(Pro+ 套餐)需 30 天预热。服务器地址:全球 https://api.sendgrid.com,欧盟区域 https://api.eu.sendgrid.com。
限制:不能用 Twilio 凭证访问 SendGrid;无 MCP 集成,需用 SDK 或 REST;Single Sender 更改地址需重新验证;域名认证需 DNS 修改权限;GET /v3/whitelabel/domains 可能返回过期条目,应按 valid: true 过滤;API Key 仅在创建时显示一次,须立即保存。安全上不要把密钥写入代码或提交到版本库,应使用密钥管理服务;若用户在对话中泄露密钥,应建议立即轮换。