How to send a test email using SendGrid API via Postman or CURL Command.

Sometimes when you're integrating our API, you might face issues sending emails. That's a great moment to start debugging using Postman and check if the API call is being correctly processed.

To create a test email using the SendGrid API in Postman, you'll need to use the API endpoint along with your SendGrid API key. Below is a basic example of how you can structure the request in Postman:

  • Set up the Request:

    • Method: POST
    • URL: https://api.sendgrid.com/v3/mail/send
    • Headers:
      • Authorization: Bearer YOUR_SENDGRID_API_KEY:
        Param s 
Type 
Authorization • 
Headers (8) 
Bearer Token 
Body 
Pre-request Script 
Tests Settings 
Heads up! These parameters hold sensitive data. TO keep this data secure While working in a collaborative environmen 
variables 
The authorizati 
header Will be automatically generated when 
you send ther uest. Learn more about authorization 7 
Token 
SG.q-31D! 
-Cdn.
      • Content-Type: application/JSON
  • Body:
    • Select the raw format and choose JSON:
    • Here's an example JSON body for a basic email:
{
"personalizations": [
{
"to": [
{
"email": "recipient@example.com"
}
]
}
],
"from": {
"email": "sender@example.com"
},
"subject": "Test subject",
"content": [
{
"type": "text/plain",
"value": "This is a test email sent via SendGrid API in Postman."
}
]
}
  • Send the Request:

Click the "Send" button in Postman to execute the request.

Please keep in mind that only 4 items are required to do a basic test according to our documentation here for this endpoint:

  • The personalizations object containing:
    • The to object containing at least one recipient email address
  • The from object containing at least one sender address
  • The subject
  • The content object that contains the type and the value

Ensure you replace YOUR_SENDGRID_API_KEY, recipient@example.com, and sender@example.com with your actual SendGrid API key, recipient email address, and sender email address respectively.

This example demonstrates a basic email structure with a plain text content type. You can modify and expand the JSON body to include more advanced features like HTML content, CC/BCC, attachments, and more as needed.

How to send a test email using CURL Command:

Please make sure to have curl installed and properly configured on your system to execute below-mentioned command.

You can send an email using SendGrid's API with curl by making a POST request to SendGrid's mail sending endpoint. You'll need to replace "YOUR_API_KEY", "from@example.com", "to@example.com", "Subject", and "Your email content" with your actual API key, sender email, recipient email, email subject, and email content respectively.

Here's an example of a curl command:

bash
curl -X "POST" "https://api.sendgrid.com/v3/mail/send" \
     -H 'Authorization: Bearer YOUR_API_KEY' \
     -H 'Content-Type: application/json' \
     -d $'{
  "personalizations": [
    {
      "to": [
        {
          "email": "to@example.com"
        }
      ],
      "subject": "Subject"
    }
  ],
  "from": {
    "email": "from@example.com"
  },
  "content": [
    {
      "type": "text/plain",
      "value": "Your email content"
    }
  ]
}'


Remember to replace YOUR_API_KEY, from@example.com, to@example.com, Subject, and Your email content with the respective values for your email.

Please make sure to have curl installed and properly configured on your system to execute this command. Also, replace the placeholder data with your actual SendGrid API key and the appropriate email addresses and content.

Have more questions? Submit a request