SendGrid example code and offline checks

Download the SendGrid examples ZIP. Extract the archive before following the commands below.

These files configure application-to-SendGrid HTTPS requests through QuotaGuard Static. They do not change SendGrid’s email-sending IP or configure SMTP.

Files

  • sendgrid_httpx.py: explicit Python HTTPX client, IP verification, non-delivering sandbox validation, and separately gated live mode.
  • sendgrid_curl.py: curl launcher with secrets supplied through standard input; IP and sandbox modes only.
  • .env.example: placeholder names and formats, not usable credentials.
  • requirements.txt: HTTPX dependency range for the Python client.
  • test_examples.py: offline unit tests. Network calls are intercepted or prohibited.

Setup

Read the full quickstart before changing SendGrid restrictions. Store real environment values through your runtime’s protected settings. Do not commit an actual .env file.

python -m pip install -r requirements.txt
python sendgrid_httpx.py ip
python sendgrid_httpx.py sandbox

Use SENDGRID_REGION=eu only for an appropriate EU regional subuser. The default is global.

The IP mode does not need a SendGrid key and sends none to the IP checker. Both dashboard addresses must appear in QG_EXPECTED_IPS, comma-separated.

Live mode

After explicit approval of the recipient and message, set SENDGRID_CONFIRM_LIVE_SEND=YES in the trusted environment, then run:

python sendgrid_httpx.py live

This requests actual email delivery. Remove the confirmation value afterward. The example requires HTTP 202 for accepted submission and makes no automatic retry. A successful submission does not establish recipient delivery.

Curl alternative

The curl helper needs Python and curl, not HTTPX:

python sendgrid_curl.py ip
python sendgrid_curl.py sandbox

Proxy and API credentials go to curl over standard input. They are removed from the child process environment and are not embedded in its argument list. The parent process still needs protected access to its environment. Do not enable shell tracing, debug logging, or general process-memory capture around secrets.

Offline tests

python -m unittest -v test_examples

The tests check request construction, configuration, and error behavior without calling SendGrid or QuotaGuard. Keep runtime verification and any approved live send separate from this suite.


Ready to Get Started?

Get in touch or create a free trial account

Back to top ↑

Copyright © 2009 - 2026 QuotaGuard. All rights reserved.