Skip to content

Add SendGrid Mail Send to the Twilio emulator - #397

Open
ctate wants to merge 2 commits into
mainfrom
ctate/add-sendgrid-mail-3d9e5b
Open

ctate wants to merge 2 commits into
mainfrom
ctate/add-sendgrid-mail-3d9e5b

Conversation

@ctate

@ctate ctate commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator
  • Serve SendGrid POST /v3/mail/send from the Twilio emulator with Bearer API keys, an empty 202 with X-Message-Id, sandbox mode, and SendGrid's errors array for every documented validation failure.
  • Store accepted mail with its sender and recipients, show it on a new SendGrid inspector tab, and test the route with the official @sendgrid/mail and @sendgrid/client packages as dev dependencies. Closes feat(twilio): emulate SendGrid Mail Send #259.

SendGrid is a Twilio product served from its own host, api.sendgrid.com.
The Twilio emulator already serves several Twilio product hosts under
one server, and Mail Send's /v3/mail/send path does not collide with
any Twilio route, so the emulator now serves it at the root.

Requests authenticate with a Bearer API key. A missing or malformed
header returns 401 "authorization required", an unknown key returns 401
"The provided authorization grant is invalid, expired, or revoked", and
a key restricted by scopes must include mail.send or gets 403 "access
forbidden". The default seed adds one key; twilio.sendgrid.api_keys adds
more with optional names and scopes.

An accepted request returns 202 with an empty body and an X-Message-Id
header, and the original body is stored with the sender and every to,
cc, and bcc recipient. Validation follows the documented Mail Send
errors and reports every problem at once in SendGrid's errors array of
message, field, and help objects: sender, personalizations and the
1,000 personalization and recipient limits, duplicate recipients,
subjects, content order with text/plain before text/html, attachments,
headers and reserved header names, categories, custom_args,
substitutions, reply_to and reply_to_list, send_at within 72 hours, ASM
groups, and mail and tracking setting types. Requests over 30 MB return
413. Sandbox mode validates and returns an empty 200 without storing
the message.

A template_id request may omit content and subject. Templates are not
rendered; the template ID and dynamic_template_data are stored as sent.
The inspector gains a SendGrid tab with captured mail and masked keys.

@sendgrid/client and @sendgrid/mail are dev dependencies used only to
test the official Node packages against the route.

Co-authored-by: Kamal Fariz Mahyuddin <269+kamal@users.noreply.github.com>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
emulate Ready Ready Preview, v0 Nov 15, 2026 7:29pm UTC

@socket-security

socket-security Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​sendgrid/​client@​8.1.610010010081100
Addednpm/​@​sendgrid/​mail@​8.1.610010010081100

View full report

Comment on lines +567 to +570
for (const [path, type, message] of checks) {
const value = getPath(settings, path);
if (value !== undefined && typeof value !== type) add(message, `${name}.${path}`);
}

@vercel vercel Bot Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-object nested settings such as mail_settings.sandbox_mode: true or tracking_settings.click_tracking: false bypass validation and return 202 instead of a validation error.

Fix on Vercel

This branch was successfully deployed

1 active deployment
Preview — be26885f Deployed Nov 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant