Skip to content

Latest commit

 

History

History
52 lines (48 loc) · 1.08 KB

personalization-without-helper-sending-single-email-single-recipient-with-cc-bcc.md

File metadata and controls

52 lines (48 loc) · 1.08 KB

Sending a Single Email to a Single Recipient With a CC and a BCC

package main

import (
  "fmt"
  "log"
  "os"

  "github.com/sendgrid/sendgrid-go"
)

func main() {
  request := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com")
  request.Method = "POST"
  request.Body = []byte(`{
  "personalizations": [{
      "to": [{
          "email": "[email protected]"
      }],
      "cc": [{
          "email": "[email protected]"
      }],
      "bcc": [{
          "email": "[email protected]"
      }],
      "substitutions": {
          "%fname%": "recipient",
          "%CustomerID%": "CUSTOMER ID GOES HERE"
      }
  }],
  "from": {
    "email": "[email protected]"
  },
  "content": [
      {
          "type": "text/html",
          "value": "<p> %fname% : %CustomerID% - Personalizations are awesome!</p>"
      }
  ]
  }`)
  response, err := sendgrid.API(request)
  if err != nil {
    log.Println(err)
  } else {
    fmt.Println(response.StatusCode)
    fmt.Println(response.Body)
    fmt.Println(response.Headers)
  }
}