Sections - Without Mail Helper Class
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": "Sections can be fun",
"substitutions": {
"-name-": "Example User",
"-city-": "Denver",
"-wel-": "-welcome-",
"-gday-": "-great_day-"
}
}
],
"from": {
"email": "[email protected] "
},
"content": [
{
"type": "text/html",
"value": "<html>\n<head>\n\t<title></title>\n</head>\n<body>\n-wel-\n<br /><br/>\nI'm glad you are trying out the Sections feature!\n<br /><br/>\n-gday-\n<br /><br/>\n</body>\n</html>"
}
],
"sections": {
"section": {
"-welcome-": "Hello -name-,",
"-great_day-": "I hope you are having a great day in -city- :)"
}
}
}` )
response , err := sendgrid .API (request )
if err != nil {
log .Println (err )
} else {
fmt .Println (response .StatusCode )
fmt .Println (response .Body )
fmt .Println (response .Headers )
}
}