We recommend using our official Go SDK, our client library with full documentation, when integrating with SendGrid's Inbound Parse Webhook.
In this example, we want to parse all emails at address@email.sendgrid.biz
and post the parsed email to http://sendgrid.biz/upload
Given this scenario, the following are the parameters you would set at the Parse API settings page:
_10Hostname: email.sendgrid.biz
_10URL: http://sendgrid.biz/upload
To test this scenario, we sent an email to example@example.com
and created the following code:
_40_40package main_40_40import (_40 "fmt"_40 "net/http"_40 "io/ioutil"_40 "log"_40 "github.com/sendgrid/sendgrid-go"_40_40)_40_40func Parse (w http.ResponseWriter, req *http.Request) {_40 //Get Email Values_40 to := req.FormValue("from")_40 subject := req.FormValue("subject")_40 body:= req.FormValue("text")_40_40 //Get Uploaded File_40 file, handler, err := req.FormFile("attachment1")_40 if err != nil {_40 fmt.Println(err)_40 }_40 data, err := ioutil.ReadAll(file)_40 if err != nil {_40 fmt.Println(err)_40 }_40 err = ioutil.WriteFile(handler.Filename, data, 0777)_40 if err != nil {_40 fmt.Println(err)_40 }_40}_40_40func main() {_40 http.HandleFunc("/upload", Parse)_40 err := http.ListenAndServe(":3000", nil)_40 if err != nil {_40 log.Fatal("ListenAndServe: ", err)_40 }_40}