Salesforce | Send email through SendGrid using REST Api


How to send an email through SendGrid using REST API in salesforce

For sending the email through Sendgrid, we must have the Sendgrid Account’s Key and this Key will use in the Rest API to send the email.

Some parameters of the Rest API are:

API: The Sendgrid’s API for sending email is –

Key: The key to the Sendgrid Account is like XX.XXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXX

Here is the example of JSON Request body of the email:

  "personalizations": [
      "to": [
          "email": ""
      "subject": "Hello, World!"
  "from": {
    "email": ""
  "content": [
      "type": "text/plain",
      "value": "Hello, This is the email body!"

Brief description of Request body parameters:

1. Personalizations: This is the array of objects. We can add only 1000 personalizations per API request.

2. To, cc and bcc: They include the recipients of the email. The total number of recipients must be less than 1000. This includes all recipients defined within the to, cc, and bcc parameters, across each object of the Personalizations array.

3. From: It includes the sender’s email address.

4. Content: It includes the type and body of the email.

Here is the code of Sendgrid Rest API in Salesforce:

        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(sendGridURL); // Send email API -
        request.setHeader('Authorization', 'Bearer ' + key); // The key of the Sendgrid Account
        request.setHeader('Content-Type', 'application/json');
        HttpResponse response = new HttpResponse();
        response = http.send(request);

Leave a Reply

Your email address will not be published.

Share on:
Share this...
Share on facebook
Share on pinterest
Share on twitter
Share on linkedin
Contact Us