Skip to contentSkip to navigationSkip to topbar
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):

Hostname: email.sendgrid.biz
URL: http://sendgrid.biz/upload

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

1
2
package main
3
4
import (
5
"fmt"
6
"net/http"
7
"io/ioutil"
8
"log"
9
"github.com/sendgrid/sendgrid-go"
10
11
)
12
13
func Parse (w http.ResponseWriter, req *http.Request) {
14
//Get Email Values
15
to := req.FormValue("from")
16
subject := req.FormValue("subject")
17
body:= req.FormValue("text")
18
19
//Get Uploaded File
20
file, handler, err := req.FormFile("attachment1")
21
if err != nil {
22
fmt.Println(err)
23
}
24
data, err := ioutil.ReadAll(file)
25
if err != nil {
26
fmt.Println(err)
27
}
28
err = ioutil.WriteFile(handler.Filename, data, 0777)
29
if err != nil {
30
fmt.Println(err)
31
}
32
}
33
34
func main() {
35
http.HandleFunc("/upload", Parse)
36
err := http.ListenAndServe(":3000", nil)
37
if err != nil {
38
log.Fatal("ListenAndServe: ", err)
39
}
40
}
41