Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Event Webhook Go Code Example



Parse Webhook

parse-webhook page anchor
(information)

Info

We recommend using our official Go SDK, our client library with full documentation, when integrating with SendGrid's Inbound Parse Webhook(link takes you to an external page).

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(link takes you to an external page):


_10
Hostname: email.sendgrid.biz


_10
URL: http://sendgrid.biz/upload

To test this scenario, we sent an email to example@example.com and created the following code:


_40
_40
package main
_40
_40
import (
_40
"fmt"
_40
"net/http"
_40
"io/ioutil"
_40
"log"
_40
"github.com/sendgrid/sendgrid-go"
_40
_40
)
_40
_40
func 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
_40
func main() {
_40
http.HandleFunc("/upload", Parse)
_40
err := http.ListenAndServe(":3000", nil)
_40
if err != nil {
_40
log.Fatal("ListenAndServe: ", err)
_40
}
_40
}


Rate this page: