Sendgrid-csharp: Subject line with spanish characters V2 .vs. V3

Created on 22 Aug 2016  路  13Comments  路  Source: sendgrid/sendgrid-csharp

Issue Summary

When using V2 SendGridMessage and assigning a value to the subject property that contains a spanish character, the email subject line shows properly in Outlook. "Informaci贸n" is the test word I have been using. In V3 SendGridHelpers.Mail and assigning a value to the subject property the letter with the acute above the "o" shows up with a black filled diamond containing a white question mark.
Maybe I am overlooking something simple, but any help would be appreciated. The body content seems to work fine.

Also, do you have a complete list of StatusCodes values returned. So far I am only seeing "BadRequest" or "Accepted".

Steps to Reproduce

  1. Send mail through SendGridMessage V2 with subject line outlined above
  2. Send mail through SendGridHelpers.Mail V3 with subject line outlined above
  3. See attached document with sample of V2 and V3 from outlook

    Technical details:

unknown or a non-library issue

Most helpful comment

I have submitted this to our team and we will be working to get it fixed. Thanks!

All 13 comments

Thanks for the bug report @nahanmail, we will investigate.

Trying to figure out a work around for this issue and further trouble shooting. Found the subject line shows correctly without any custom args, but when you add custom args with either the helper class or JSON it no longer formats correctly. Rolling out to test for client this week. We have to use custom args for tracking. Do I have to use V2?

@nahanmail,

I would suggest that, since I can not guarantee we will have it fixed this week.

Ok, after trying different things with add custom arguments, I started researching subject line encoding. Found RFC1342 with the use of =?charset?encoding?encoded-text?=, so I tried with subject line and SendGrid dropped them because of invalid header. Kept searching and found that String.Normalize worked and worked whether or not I had custom arguments.

EmailSubject is a string from value from a class.
mail.Subject = EmailSubject.Normalize(System.Text.NormalizationForm.FormKD);

This is working so I should be good with this work around for now.

Thanks.

Thanks for sharing the workaround with us!

Please email us at [email protected] with your mailing address and T-shirt size so we can send you some swag.

I have the same issue. This workaround does not fix it for me. I found that the course of the issue is that I add some custom args. After doing so, Sendgrid fails to UTF-8 encode the subject part of the email. comparison:

With:
Subject: Invitation til deltagelse i sp???rgeskemaunders???gelse

Without:
Subject: =?UTF-8?B?SW52aXRhdGlvbiB0aWwgZGVsdGFnZWxzZSBpIHNww7hyZ2Vza2VtYXVuZGVycw==?=
=?UTF-8?B?w7hnZWxzZQ==?=

I have the same issue with German "Umlaute" (枚盲眉). They don't work anymore in version 8.0.5 while they have worked in 6.3.4. The workaround above does fix it for some email accounts but breaks it for other accounts (e.g. Exchange accounts) using Outlook.

It seems that the problem is not the library bug. Because I could reproduce without the library.
Here is my workaround. I hope this will be help.

My workaround is adding substitution key which value is empty in the Subject header when you use substitutions with non-ASCII character Subject. Here is full body of the request. I think you can create the body with the mail helper.

{
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]"
        }
      ],
      "subject": "Informaci贸n%subkey%",
      "substitutions": {
        "%subkey%": ""
      }
    }
  ],
  "from": {
    "email": "[email protected]"
  },
  "content": [
    {
      "type": "text/plain",
      "value": "Hello"
    }
  ]
}

Thank you awwa. I can confirm that the workaround works. Here is the C# code:

message.Subject = subject + "%subkey%";
Personalization personalization = new Personalization();
personalization.AddSubstitution("%subkey%", "");
message.AddPersonalization(personalization);

Great, that workaround fixed it. Thanks!

I have submitted this to our team and we will be working to get it fixed. Thanks!

To add more to this subject, it seems SendGrid (or subsequent services) is somehow encoding subjects only partially.

While using SendGrid v9.12.6 on .Net core 3.1 and sending an email with a french subject:
"Votre th茅rapeute a modifi茅 votre compte."
The subject gets encoded that way:
Subject: Votre =?UTF-8?B?dGjDqXJhcGV1dGUgYSBtb2RpZmnDqQ==?= votre compte.
which gives a broken subject.
Normalizing the subject string does change the subject response but still always give a partially encoded and broken title.

I do believe that encoding the full subject instead of encoding part of it will fix the bug in this specific case, if it can be of any help.
Cheers,

Closing this as it has been marked a non-library issue.

Was this page helpful?
0 / 5 - 0 ratings