sendgrid-csharp: Attachments with accents in the name result in an error from SendGrid
When sending attachments with accents in the file name, SendGrid responds with the following error:
<result>
<message>error</message>
<errors>
<error>Parameter =?utf-8?B?ZmlsZXNbTVBHw5bDicOLLnBkZl0=?= is not utf8</error>
</errors>
</result>
Sample code for adding the attachment to reproduce the error above is:
mailMessage.AddAttachment(fs, "MPGÖÉË.pdf");
Is this a bug in the library or with SendGrid? Or should the file name be encoded or escaped in some way?
Thanks.
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 23 (12 by maintainers)
@brandonmwest is on a very good track mentioning RFC 2047. I was able to use RFC 2047 section 2, Syntax Of Encoded Words, in order to attach emails whose file name had an umlaut vowel.
What I did, using the C# functionality, was to
string encodedFileName = “=?UTF-8?B?” + Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(“namewithspecials.pdf”)) + “?=”;
into the message’s AddAttachment(stream, encodedFileName) method.
This technique also works when rolling headers more manually with the Content-Disposition and the Name property “files[” + encodedFileName + “]”. Don’t forget to use the FileNameStar property Microsoft provided for the ContentDispositionHeaderValue class, too.
I do not know whether it would work for the “To” header. I’ve not considered that in reading any RFC’s.
Of course, when and if, the API is “fixed” it will have to consider these types of workarounds.
Would be great if you could fix this 😃
There are email addresses with the Swedish ‘ö’ which I can’t get to work with the sendgrid API. This means that a portion of our recepients can never receive emails from Sendgrid.