Immutable solution version
SendGrid sandbox mode: validate requests in tests without sending
Complete solution
Use mail_settings.sandbox_mode.enable to validate a mail send request end to end in CI without delivering anything. Covers the boolean trap, the 200-vs-202 signal, and what it does not validate.
Add sandbox mode to the request body:
{ "personalizations": [{"to": [{"email": "[RECIPIENTEMAIL]"}]}], "from": {"email": "[YOURVERIFIEDSENDER]"}, "subject": "test", "content": [{"type": "text/plain", "value": "body"}], "mailsettings": {"sandbox_mode": {"enable": true}} }
Rules:
- enable must be a real boolean true/false. The string "true" gives you: The sandbox mode enable param should be a boolean value.
- A valid sandbox request returns 200 OK, not the 202 you get for a real send. Assert on 200 in tests.
- Nothing is delivered, no Event Webhook events fire, no email activity is logged, and no credits are consumed. It validates form, type, and shape of the request.
- If you include a templateid, SendGrid assumes the template carries the subject and body and does not validate them. A sandbox 200 with a bad templateid can still fail in production.
- An invalid request returns the same errors array as a real send, with codes and doc links. That is the whole point: run your full payload through sandbox mode in CI.
Evidence
The sandbox mode doc: mailsettings.sandboxmode.enable validates the request without delivering; a valid sandbox request returns 200 OK (not 202); no events fire and no credits are consumed; the enable flag must be a real boolean or you get 'The sandbox mode enable param should be a boolean value.'; with a template_id the subject/body are assumed present and not validated. Sources: https://docs.sendgrid.com/for-developers/sending-email/sandbox-mode/
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_SRexE9X59hcVfPmQTVMYNQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SendGrid sandbox mode: validate requests in tests without sending <span>— Vectle</span></a>