Repository navigation
Open
Labels
status: help wantedrequesting help from the communityrequesting help from the communitytype: bugbug in the librarybug in the library
Description
Issue Summary
The example in the readme for helper/inbound does not work.
Steps to Reproduce
- Cut and Paste Example
- Run Code
- Point a parser domain to it
- Send email to address@parser.domain
Code Snippet
package main
import (
"fmt"
"log"
"net/http"
"github.com/sendgrid/sendgrid-go/helpers/inbound"
)
func inboundHandler(response http.ResponseWriter, request *http.Request) {
parsedEmail := inbound.Parse(request)
fmt.Print(parsedEmail.Headers["From"])
for filename, contents := range parsedEmail.Attachments {
// Do something with an attachment
//handleAttachment(filename, contents)
fmt.Print(filename, contents)
}
for section, body := range parsedEmail.Body {
// Do something with the email body
//handleEmail(body)
fmt.Print(section, 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")
}
}
Exception/Log
2020/07/02 16:51:40 http: panic serving 10.244.0.50:40980: runtime error: index out of range [1] with length 1
goroutine 21 [running]:
net/http.(*conn).serve.func1(0xc000072f00)
/usr/local/go/src/net/http/server.go:1772 +0x139
panic(0x6d76a0, 0xc0001d8780)
/usr/local/go/src/runtime/panic.go:975 +0x3e3
github.com/sendgrid/sendgrid-go/helpers/inbound.(*ParsedEmail).parseHeaders(0xc0000cb630, 0xc000143c00, 0xb14)
/go/src/github.com/sendgrid/sendgrid-go/helpers/inbound/inbound.go:100 +0x19c
github.com/sendgrid/sendgrid-go/helpers/inbound.(*ParsedEmail).parse(0xc0000cb630)
/go/src/github.com/sendgrid/sendgrid-go/helpers/inbound/inbound.go:40 +0x180
github.com/sendgrid/sendgrid-go/helpers/inbound.Parse(...)
/go/src/github.com/sendgrid/sendgrid-go/helpers/inbound/inbound.go:28
main.inboundHandler(0x7637c0, 0xc0000a4700, 0xc0000c0900)
/go/src/app/main.go:20 +0x1b1
net/http.HandlerFunc.ServeHTTP(0x70fca0, 0x7637c0, 0xc0000a4700, 0xc0000c0900)
/usr/local/go/src/net/http/server.go:2012 +0x44
net/http.(*ServeMux).ServeHTTP(0x93e300, 0x7637c0, 0xc0000a4700, 0xc0000c0900)
/usr/local/go/src/net/http/server.go:2387 +0x1a5
net/http.serverHandler.ServeHTTP(0xc0000a4000, 0x7637c0, 0xc0000a4700, 0xc0000c0900)
/usr/local/go/src/net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc000072f00, 0x763d80, 0xc00004cb80)
/usr/local/go/src/net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2933 +0x35c
Technical details:
- sendgrid-go version: Latest
- go version: 1.14
Reacted by Henrique Vicente, Gary and alicanyildirim
Metadata
Metadata
Assignees
Labels
status: help wantedrequesting help from the communityrequesting help from the communitytype: bugbug in the librarybug in the library
Activity
eshanholtz commentedon Jul 6, 2020
@phillipbroberts
Looks like it's having an issue parsing the email header portion. Can you please include an example of the inbound email request body so I can run further tests?
phillipbroberts commentedon Jul 8, 2020
I didn't have the service up anymore - the best I could do is send an email from the address I was using to send test emails to one of my other email addresses - hope this is helpful.
eshanholtz commentedon Jul 14, 2020
I was able to recreate this bug. This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.
kwshi commentedon Dec 21, 2020
For whoever gets around to working on this (I may try to open a PR later if I'm free), I dug around a little and think I figured out the cause of the issue (or at least the cause of an issue):
sendgrid-go/helpers/inbound/inbound.go
Line 36 in 52264b8
I wrote a quick program that logs the keys of the
req.MultipartForm.Valuemap, producing the following:Point being, there is no
"email"field. Instead, it appears that much of the informationparseRawEmailtries to extract, e.g. attachments, text content, etc., are already pre-extracted by the inbound parse hook and provided in the"attachments","attachment-info","text", etc. keys.That also means that the documentation (specifically the "sample payload" snippet) here should be updated to reflect the actual payload shape.