sendgrid-go: Send mail failed with v3 API and multi-byte contents.
Issue Summary
We can’t send a mail via v3 API with multibyte content.
Steps to Reproduce
func TestSendGrid_bare(t *testing.T) {
m := mail.NewV3Mail()
m.SetFrom(mail.NewEmail("日本語名1", "foobar@example.com"))
m.Subject = "日本語タイトル"
m.AddContent(mail.NewContent("text/html", "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"))
p := mail.NewPersonalization()
p.AddTos(mail.NewEmail("日本語名2", "fizzbuzz@example.com.com"))
m.AddPersonalizations(p)
request := sendgrid.GetRequest("<my api key>", "/v3/mail/send", "https://api.sendgrid.com")
request.Method = "POST"
request.Body = mail.GetRequestBody(m)
response, err := sendgrid.API(request)
if err != nil {
t.Error(err)
} else if response.StatusCode < 200 || 300 <= response.StatusCode{
t.Error(response.StatusCode)
t.Error(response.Body)
t.Error(response.Headers)
} else {
t.Log(response.StatusCode)
t.Log(response.Body)
t.Log(response.Headers)
}
}
func TestSendGrid_emoji(t *testing.T) {
m := mail.NewV3Mail()
m.SetFrom(mail.NewEmail("foo", "foobar@example.com"))
m.Subject = "title"
m.AddContent(mail.NewContent("text/plain", "🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸🐱😸"))
p := mail.NewPersonalization()
p.AddTos(mail.NewEmail("fizzbuzz", "fizzbuzz@example.com"))
m.AddPersonalizations(p)
request := sendgrid.GetRequest("<my api key>", "/v3/mail/send", "https://api.sendgrid.com")
request.Method = "POST"
request.Body = mail.GetRequestBody(m)
response, err := sendgrid.API(request)
if err != nil {
t.Error(err)
} else if response.StatusCode < 200 || 300 <= response.StatusCode{
t.Error(response.StatusCode)
t.Error(response.Body)
t.Error(response.Headers)
} else {
t.Log(response.StatusCode)
t.Log(response.Body)
t.Log(response.Headers)
}
}
=== RUN TestSendGrid_bare
--- FAIL: TestSendGrid_bare (0.89s)
sendgrid_test.go:30: 415
sendgrid_test.go:31: {"errors":[{"message":"Unrecognized UTF8 Byte at position 511","field":null,"help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#-Encoding-Errors"}]}
sendgrid_test.go:32: map[Server:[nginx] Date:[Thu, 23 Jun 2016 04:21:42 GMT] Content-Type:[application/json] Content-Length:[171] Connection:[keep-alive] X-Frame-Options:[DENY]]
=== RUN TestSendGrid_emoji
--- FAIL: TestSendGrid_emoji (0.09s)
sendgrid_test.go:59: 415
sendgrid_test.go:60: {"errors":[{"message":"Unrecognized UTF8 Byte at position 511","field":null,"help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#-Encoding-Errors"}]}
sendgrid_test.go:61: map[Content-Length:[171] Connection:[keep-alive] X-Frame-Options:[DENY] Server:[nginx] Date:[Thu, 23 Jun 2016 04:21:42 GMT] Content-Type:[application/json]]
Technical details:
- sendgrid-go Version: master (latest commit: [21f08698ba61551befffd8755f508631a4d1e8ae])
- Go Version: 1.6.2
I’m posted this issue to SendGrid support. Request # 691762
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 6
- Comments: 15 (8 by maintainers)
@thinkingserious I think this issue is not client side bug. It can reproduce by cURL.
@norbergj,
I don’t have an ETA, but the continued comments and votes help move it up the queue. Also, I will be advocating again for a quick fix today at our stand up.
@Rompei,
Thanks! I’ll pass this along to the team.
@thinkingserious I got the same problem when I try to send email written in Japanese then email was not delivered and the error was appeared.
I think it is caused by the length of body. Please see the examples below.
It’s ok. but
It outputs the error
And, it’s appeared in a byte of 2 of the multiplier - 1, for example 511 and 1023.
I hope it will be your help, and I use v2.0.0 with glide until it be fixed.