package
3.10.5+incompatible
Repository: https://github.com/mewis/sendgrid-go.git
Documentation: pkg.go.dev
# README
This helper is a stand-alone module to help get you started consuming and processing Inbound Parse data.
Table of Contents
Example Usage
package main
import (
"fmt"
"log"
"net/http"
"github.com/sendgrid/sendgrid-go/helpers/inbound"
)
func inboundHandler(response http.ResponseWriter, request *http.Request) {
parsedEmail, err := Parse(request)
if err != nil {
log.Fatal(err)
}
fmt.Print(parsedEmail.Headers["From"])
for filename, contents := range parsedEmail.Attachments {
// Do something with an attachment
handleAttachment(filename, contents)
}
for section, body := range parsedEmail.Body {
// Do something with the email body
handleEmail(body)
}
// Twilio SendGrid needs a 200 OK response to stop POSTing
response.WriteHeader(http.StatusOK)
}
func main() {
http.HandleFunc("/inbound", inboundHandler)
if err := http.ListenAndServe(":8000", nil); err != nil {
log.Fatalln("Error")
}
}
Testing the Source Code
Tests are located in the helpers/inbound
folder:
Learn about testing this code here.
Contributing
If you would like to contribute to this project, please see our contributing guide. Thanks!
# Functions
Parse parses an email using Go's multipart parser and populates the headers, and body This method skips processing the attachment file and is therefore more performant.
ParseWithAttachments parses an email using Go's multipart parser and populates the headers, body and processes attachments.
# Structs
EmailAttachment defines information related to an email attachment.
ParsedEmail defines a multipart parsed email Body and Attachments are only populated if the Raw option is checked on the SendGrid inbound configuration and are named for backwards compatability.