Skip to content

Latest commit

 

History

History
51 lines (47 loc) · 1.12 KB

personalization-without-helper-sending-two-emails-to-two-groups-recipients-from-two-different-from-emails.md

File metadata and controls

51 lines (47 loc) · 1.12 KB

Personalization (without helper) - Sending Two Different Emails to Two Different Groups of Recipients from two different From email address

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]"
      }],
      "subject": "YOUR SUBJECT LINE GOES HERE"
  }, {
      "to": [{
          "email": "[email protected]"
      }],
      "from": {
          "email": "[email protected]"
      },
      "subject": "YOUR OTHER SUBJECT LINE GOES HERE"
  }],
  "from": {
    "email": "[email protected]"
  },
  "content": [
      {
          "type": "text/html",
          "value": "<p>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)
  }
}