For more information about Subusers, visit the longform Subusers documentation. You can also manage Subusers in the SendGrid console.
This guide provides a step-by-step process on how to create a regional subuser using the Twilio SendGrid API, specifically for the European Union (EU) region. By following this guide, you will be able to set up a subuser, configure necessary settings, and send emails from the EU region.
Before you begin, ensure you have the following:
Create a subuser that is bound to the EU region. When creating the subuser, specify the region as eu
.
1curl -X POST "https://api.sendgrid.com/v3/subusers" \2--header "Authorization: Bearer $YOUR_API_KEY" \3--header "Content-Type: application/json" \4--data '{"username":"John@example.com","email":"John@example.com","password":"johns_password","region":"eu","include_region":true}'
You can add one IP address per month via self-service. The following command adds an EU-based IP address and assigns it to the subuser and parent accounts.
1curl -H "Authorization: Bearer $YOUR_API_KEY" -X POST \2'https://api.sendgrid.com/v3/send_ips/ips' -d '{"is_auto_warmup":false, "is_parent_assigned":true, "subusers":["12345678"], "region":"eu", "include_region":true}'
Configure Domain Authentication by adding a record to your DNS host. Follow these steps to complete Domain Authentication:
1curl -X POST "https://api.sendgrid.com/v3/whitelabel/domains" \2--header "Authorization: Bearer $YOUR_API_KEY" \3--header "Content-Type: application/json" \4--data '{"domain": "example.com", "region": "eu"}'
1curl -X POST "https://api.sendgrid.com/v3/whitelabel/domains/{DOMAIN_ID}/validate" \2--header "Authorization: Bearer $YOUR_API_KEY"
1curl -X POST "https://api.sendgrid.com/v3/whitelabel/domains/{DOMAIN_ID}/subuser" \2--header "Authorization: Bearer $YOUR_API_KEY" \3--header "Content-Type: application/json" \4--data '{"username":"jdoe"}'
Create an API key for your EU-based subuser via the Twilio SendGrid Console or the API. This key should have the mail.send
permission.
1curl -X POST "https://api.sendgrid.com/v3/api_keys" \2--header "Authorization: Bearer $YOUR_API_KEY" \3--header "Content-Type: application/json" \4--data '{"name":"MyEU API Key", "scopes":["mail.send","alerts.create","alerts.read"]}'
Now that you have an API Key for your EU subuser, you can use that subuser to send email. Make sure to send email using the base URL api.eu.sendgrid.com
.
curl --request POST --url https://api.eu.sendgrid.com/v3/mail/send --header 'Authorization: Bearer $YOUR_API_KEY' --header 'Content-Type: application/json' --data '{"personalizations":[{"to":[{"email":"recipient@example.com"}]}],"from":{"email":"sender@example.com"},"subject":"Hello, World!","content":[{"type":"text/plain","value":"Heya!"}]}'
By following these steps, you have successfully created a regional subuser in the EU, configured necessary settings, and sent an email. This setup helps in complying with data residency requirements by ensuring that the data does not leave the EU region.
For more detailed information, refer to the original blog post: Regional Email Public Beta: Set Up a Subuser and IP Address in the EU.