SendGrid - Sending email using cURL

by
Jeremy Canfield |
Updated: November 25 2024
| SendGrid articles
You will need an API Key such as SG.abcdefg123456789abcdefg123456789abcdefg123456789abcdefg123456789abcde to create an email using SendGrid and Python. At https://sendgrid.com/ select Email API > Integration Guide > Web App > Python and create an API key. This is your one and only chance to make note of the API Key, so make note of it now!
Or, you can Create email using REST API. You can also List your API Keys using the REST API.
curl --header "Authorization: Bearer SA.14Hj6fh1RBSXoatMt4f5hg.zOhdOFKuitjqOtWatZXmGefxDMFDWIIElNhe7vb78z9" --request GET --url https://api.sendgrid.com/v3/api_keys
Something like this should be returned.
{
"result": [
{
"name": "default API Key for smtp.sendgrid.net relay",
"api_key_id": "xyz123456789xyz1234567"
},
{
"name": "default",
"api_key_id": "abcdefg123456789abcdef"
}
]
}
When testing/debugging, you can probably set the API key to Full Access. At https://sendgrid.com/ select Settings > API Keys > edit API Key and ensure Full Access is selected.
Send your first email.
curl \
--request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header "Authorization: Bearer SG.abcdefg123456789abcdefg123456789abcdefg123456789abcdefg123456789ab" \
--header 'Content-Type: application/json' \
--data '{"personalizations": [{"to": [{"email": "test@example.com"}]}],"from": {"email": "test@example.com"},"subject": "Sending with SendGrid is Fun","content": [{"type": "text/plain", "value": "and easy to do anywhere, even with cURL"}]}'
Did you find this article helpful?
If so, consider buying me a coffee over at