Sendgrid-csharp: Send mail failed with v3 API and multi-byte contents

Created on 5 Jul 2016  ·  9Comments  ·  Source: sendgrid/sendgrid-csharp

I face the same problem with https://github.com/sendgrid/sendgrid-go/issues/66
Mail content that contains emoji got error message "Unrecognized UTF8 Byte at position ..."
Any update on this issue?

Thanks :)

help wanted bug

Most helpful comment

The fix for this has been deployed :)

Thank you for your patience!

All 9 comments

Any update?

I think the issue come from the Get() method in Mail Helper class
JsonConvert.SerializeObject(this, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore, StringEscapeHandling = StringEscapeHandling.EscapeHtml });,
after serialize I have this result

{"from":{"name":"myXteam","email":"[email protected]"},"subject":"[MyXteam] Bạn đã tạo đơn hàng đăng kí gói sử dụng thành công","personalizations":[{"to":[{"email":"[email protected]"}],"custom_args":{"contactId":"0"}}],"content":[{"type":"text/html","value":"\u003cdiv style=\u0022width: 700px; margin: auto\u0022\u003e \u003cdiv style=\u0022background-color: #3a79be; padding: 10px\u0022\u003e\u003ca href=\u0022http://app.myxteam.com\u0022\u003e \u003cimg src=\u0022http://app.myxteam.com/images/title.png\u0022/\u003e \u003c/a\u003e\u003c/div\u003e\u003cdiv\u003e\u003ctable\u003e \u003ctbody\u003e \u003ctr\u003e \u003cth colspan=\u00224\u0022\u003eThông tin đơn hàng\u003c/th\u003e \u003c/tr\u003e\u003ctr class=\u0022info\u0022\u003e \u003ctd style=\u0022width:150px\u0022\u003eMã đơn hàng\u003c/td\u003e\u003ctd colspan=\u00223\u0022\u003e\u003cb class=\u0022text-danger\u0022\u003e3-12759-NWMV8\u003c/b\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr class=\u0022info\u0022\u003e \u003ctd\u003eGói đăng ký\u003c/td\u003e\u003ctd style=\u0022width:220px\u0022\u003e\u003cb\u003eGói Platinum\u003c/b\u003e\u003c/td\u003e\u003ctd style=\u0022width:180px\u0022\u003eGiá gói\u003c/td\u003e\u003ctd class=\u0022text-right\u0022\u003e\u003cb\u003e500,000 đ\u003c/b\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr class=\u0022info\u0022\u003e \u003ctd\u003eSố tháng\u003c/td\u003e\u003ctd\u003e\u003cb\u003e122\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eTổng tiền\u003c/td\u003e\u003ctd class=\u0022text-right\u0022\u003e\u003cb\u003e6,000,000 đ\u003c/b\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr class=\u0022info\u0022\u003e \u003ctd\u003eChiết khẩu\u003c/td\u003e\u003ctd\u003e\u003cb\u003e0 %\u003c/b\u003e\u003c/td\u003e\u003ctd\u003eChiết khấu từ gói cũ\u003c/td\u003e\u003ctd class=\u0022text-right\u0022\u003e\u003cb class=\u0022text-danger\u0022\u003e0 đ\u003c/b\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr class=\u0022info\u0022\u003e \u003ctd\u003eSố tiền cần thanh toán\u003c/td\u003e\u003ctd\u003e\u003cb class=\u0022text-danger\u0022\u003e6,000,000 đ\u003c/b\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e \u003cth colspan=\u00224\u0022\u003eThông tin thanh toán\u003c/th\u003e \u003c/tr\u003e\u003ctr class=\u0022info\u0022\u003e \u003ctd\u003eNgày tạo\u003c/td\u003e\u003ctd colspan=\u00223\u0022\u003e2016-07-08 13:03:08\u003c/td\u003e\u003c/tr\u003e\u003ctr class=\u0022info\u0022\u003e \u003ctd\u003eCách thanh toán\u003c/td\u003e\u003ctd colspan=\u00223\u0022\u003e \u003cdiv style=\u0022border:0\u0022\u003e Phương thức thanh toán Chuyển khoản qua Ngân hàng \u003c/div\u003e\u003cdiv class=\u0022text-warning\u0022\u003e Bạn vui lòng chuyển khoản số tiền \u003cb\u003e6,000,000 đ\u003c/b\u003e vào 1 trong các tài khoản bên dưới và nhập Mã đơn hàng (\u003cb\u003e3-12759-NWMV8\u003c/b\u003e) vào nội dung chuyển khoản. Chúng tôi sẽ chuyển đổi gói sử dụng của bạn sớm nhất ngay khi nhận được thông tin chuyển khoản. \u003c/div\u003e\u003cdiv\u003eChủ tài khoản: \u003cb\u003eCông ty Cổ Phần MyXteam\u003c/b\u003e\u003c/div\u003e\u003cdiv\u003eSố tài khoản: \u003cb\u003e0071000945247\u003c/b\u003e\u003c/div\u003e\u003cdiv\u003eTên ngân hàng: \u003cb\u003eNgân hàng TMCP Ngoại Thương Việt Nam (VietComBank)\u003c/b\u003e\u003c/div\u003e\u003cdiv\u003ehoặc\u003c/div\u003e\u003cdiv\u003eChủ tài khoản: \u003cb\u003eNguyễn Lưu Quốc\u003c/b\u003e\u003c/div\u003e\u003cdiv\u003eSố tài khoản: \u003cb\u003e14256349\u003c/b\u003e\u003c/div\u003e\u003cdiv\u003eTên ngân hàng: \u003cb\u003eNgân hàng TMCP Á Châu (ACB)\u003c/b\u003e\u003c/div\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e \u003c/table\u003e\u003c/div\u003e\u003cdiv style=\u0022margin-top: 30px\u0022\u003e \u003ch3 style=\u0022margin-top: 60px; color: #666\u0022\u003eNếu bạn chưa cài đặt ứng dụng MyXTeam, bạn có thể cài đặt ứng dụng trên các thiết bị sau: \u003c/h3\u003e \u003cdiv style=\u0022margin-top: 10px; padding: 10px 0px; background-color: #FFF; text-align: center\u0022\u003e \u003ca href=\u0022https://play.google.com/store/apps/details?id=epapersmart.teamwork\u0022\u003e \u003cimg src=\u0022http://app.myxteam.com/images/GooglePlay.png\u0022\u003e\u003c/a\u003e \u003ca href=\u0022https://itunes.apple.com/us/app/myxteam-lam-viec-cong-tac/id942417318?ls=1\u0026mt=8\u0022\u003e \u003cimg src=\u0022http://app.myxteam.com/images/AppStore.png\u0022\u003e \u003c/a\u003e \u003c/div\u003e\u003cdiv style=\u0022color: gray; margin-top: 30px; font-size: 13px\u0022\u003eBạn nhận được mail này là do bạn đã yêu cầu khôi phục mật khẩu trên ứng dụng MyXTeam. Nếu có nhầm lẫn hay sai sót nào, bạn có thể bỏ qua email này hoặc phản hồi lại với chúng tôi \u003ca href=\u0022mailto:[email protected]\u0022\[email protected]\u003c/a\u003e \u003c/div\u003e\u003c/div\u003e"}],"custom_args":{"customerAccountNumber":"support_at_myxteam.com","sendId":"113"},"tracking_settings":{"click_tracking":{"enable":true},"open_tracking":{"enable":true},"subscription_tracking":{"enable":true}},"reply_to":{"email":"[email protected]"}}

and it fail with error message: `{"errors":[{"message":"Unrecognized UTF8 Byte at position 2046","field":null,"help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#-Encoding-Errors"}]}

So I'm replace the Get() method with default option JsonConvert.SerializeObject(this), it sent successfully
But using JsonConvert.SerializeObject(this) cause apostrophe issue

Thanks for checking in! The engineering team has this on their backlog to fix and I'm monitoring it multiple times per day. As soon as its fixed, I will ping you here.

I believe this is a server-side issue. It has to do with where the multi-byte character is in the content. It seems as if the server or validator reads in chunks of 512 bytes, and if the unicode character (multibyte) happen to come in between byte 511 and 512 it will fail. I have narrowed it down to this simple request, that fails when the norwegian letter å is in this position. Adding one more number and it is accepted.

POST https://api.sendgrid.com/v3/mail/send HTTP/1.1
Host: api.sendgrid.com
Connection: keep-alive
Content-Length: 607
Accept: application/json, application/json
Cache-Control: no-cache
Content-Type: application/json; charset=UTF-8

{"from":{"name":"My sender","email":"[email protected]"},"subject":"Test subject","personalizations":[{"to":[{"name":"YourName","email":"[email protected]"}]}],"content":[{"type":"text/html","value":"123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 spørsmål"}],"categories":["Transactional","Test"],"mail_settings": {"sandbox_mode":{"enable": true}}}

@dag-oyvind You are correct, it is a server-side issue that is currently being fixed. I will be updating this thread when the fix is pushed live.

Thanks for providing some additional detail!

Same problem here. We cannot use latest SendGrid 8.0.0 lib in production because of this issue.
Any updates?

@alxbog,

This issue is being fixed in the current sprint and is now actively being worked on. As soon as the fix lands in production I'll be posting an update here.

Any update?

@baphomette,

As of right now, it looks like this fix is scheduled to be released today.

The fix for this has been deployed :)

Thank you for your patience!

Was this page helpful?
0 / 5 - 0 ratings