Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send mail fails with BadRequest when apostrophe used in sender name #232

Closed
RyanONeill1970 opened this issue Jun 12, 2016 · 11 comments
Closed
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@RyanONeill1970
Copy link

On line 26 of Example.cs in the demonstration project for betav3 we have the sender email address.

If we add a name, it mostly works unless you happen to have a surname with an apostrophe in.

For example, these work;
Email from = new Email("[email protected]");
Email from = new Email("[email protected]". "Ryan");

The following result in a BadRequest status code.
Email from = new Email("[email protected]", "Ryan O'Neill");
Email from = new Email("[email protected]", "Ryan O\'Neill");

The output from the console test app is;

BadRequest
{"errors":[{"message":"Bad Request","field":null,"help":null}]}
Connection: keep-alive
X-Frame-Options: DENY
Date: Sun, 12 Jun 2016 22:10:24 GMT
Server: nginx

I'm not certain where the issue is, in the client wrapper or at the server. I suspect both because I have been able to bypass the client and directly post to the server, generating an email by escaping the apostrophe but it comes out as a double apostrophe.

@thinkingserious thinkingserious added type: bug bug in the library status: help wanted requesting help from the community labels Jun 13, 2016
@thinkingserious
Copy link
Contributor

Hello @RyanONeill1970,

Thanks for bringing this issue to our attention. We will take a look and find out where the fix should happen.

@RyanONeill1970
Copy link
Author

I've been playing with this and can confirm that there is an error in the v3 API endpoint https://api.sendgrid.com/v3/mail/send.

There may be other errors in the client, but I am bypassing that for this test.

I have been posting the following JSON which results in a bad request response code. Removing the apostrophe in the senders surname makes it work.

{"personalizations":[{"to":[{"email":"[email protected]"}],"subject":"my subject"}],"from":{"email":"[email protected]","name":"Ryan O'Neill"},"content":[{"type":"text/plain","value":" "}],"template_id":"d6a75e38-1111-2222-904c-13e9103de025"}

The raw response from the API endpoint;

{"errors":[{"message":"Bad Request","field":null,"help":null}]}

A not great workaround is to use a back tick in place of the apostrophe.

@thinkingserious
Copy link
Contributor

thinkingserious commented Jun 27, 2016

Hi @RyanONeill1970,

I believe the "Bad Request" in this case is because the subject is inside of the personalizations block, instead do:

{
  "content": [
    {
      "type": "text/plain",
      "value": " "
    }
  ],
  "from": {
    "email": "[email protected]",
    "name": "Ryan O'Neill"
  },
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]"
        }
      ]
    }
  ],
  "subject": "my subject",
  "template_id": "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
}

When I try this via a cURL request the apostrophe is handled correctly, meaning the issue is not with the api call. I will now test the library to see where the error is.

How were you trying the call outside of the library?

Here is how I did it:

curl -X "POST" "https://api.sendgrid.com/v3/mail/send" -H "Authorization: Bearer $SENDGRID_API_KEY" -H "Content-Type: application/json" -d @post.json

Where the post.json file has the above content.

@PandaBoy00
Copy link

The issue is that the single quote ( ' ) isn't support in the Content object either during my testing. The workaround for this issue is that you can use the ` character and your code should work. To be clear, that is the character that is under the tilde character on a US Keyboard layout.

@RayHAz
Copy link

RayHAz commented Jun 28, 2016

The following (slightly modified from the Readme example) also generates BadRequest:
Content content = new Content("text/plain", "We'll eventually get more information in here!");
Changing "We'll" to "We will" fixes it.
I read in another issue recommending "encoding" it, but that was using text/html. This is text/plain. What sort of encoding should be used? I've tried C# string with , HTML with ' and '... neither has worked for text/plain content.

@thinkingserious
Copy link
Contributor

I have a fix deploying today @RyanONeill1970 and @RayHAz, thanks for hanging in there with me :)

#257

@thinkingserious
Copy link
Contributor

@RyanONeill1970 @RayHAz,

Here is the fix: https://www.nuget.org/packages/Sendgrid/7.0.3

Thanks again!

@manju-webner
Copy link

Hello guys, I am also facing the similar problem while using apostrophe in the fromname field in one of our php project. When I use the text like "Webner's" in fromname, it just shows "Webners" as a sender name in the email sent. I am using both the methods (using curl-post request and using php library of sendgrid), but I am facing the same problem with both of them. Please provide any solution how should I do this. Thanks in advance.

Manju Kashyap

@thinkingserious
Copy link
Contributor

Hello @manju-kk,

Would you mind opening a new issue with the following information?

  1. Version of this library you are using.
  2. Version of .NET you are using.
  3. A code snippet to give context.

Thanks!

@vivekbhandari279
Copy link

If you are passing not string value then SendGrid will give you 👇

{"errors":[{"message":"Bad Request","field":null,"help":null}]}

Convert your all non-string value to string before sending to the template file.

Happy Coding 😊

@Lucifar2
Copy link

Lucifar2 commented May 7, 2022

Hello @vivekbhandari279 ,
I am trying to make a POST request to sendgrid V3 API but it keeps showing me the below error :

{"errors":[{"message":"Bad Request","field":null,"help":null}]}curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
I am a bit lost. Could you please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

7 participants