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

I can not send email with accents #239

Closed
eaparango opened this issue Jun 15, 2016 · 3 comments
Closed

I can not send email with accents #239

eaparango opened this issue Jun 15, 2016 · 3 comments
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@eaparango
Copy link

Issue Summary

I can not send email with accents

Steps to Reproduce

var helper = sendgrid.mail;
var mail = new helper.Mail();
var personalization = new helper.Personalization();
var email = new helper.Email("[email protected]", "Fracttal");

mail.setFrom(email);
mail.setSubject("Servidor áéíóúÑñáéíóúÑñáéíóúÑñ");

email = new helper.Email("[email protected]", "áéíóúÑñáéíóúÑñáéíóúÑñáéíóúÑñ");
personalization.addTo(email);

mail.addPersonalization(personalization);

var content = new helper.Content("text/plain", "Servidor áéíóúÑñáéíóúÑñáéíóúÑñ: " + new Date());
mail.addContent(content);

var sg = sendgrid.SendGrid("xxxxxxxxxxxxxxxxxxx");
var requestPost = sendgrid.emptyRequest;
requestPost.method = 'POST';
requestPost.path = '/v3/mail/send';
requestPost.body = mail.toJson();
sg.API(requestPost, function (response) {
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
});

ERROR:
400
{"errors":[{"message":"Bad Request","field":null,"help":null}]}
{ server: 'nginx',
date: 'Wed, 15 Jun 2016 16:14:22 GMT',
'content-type': 'application/json',
'content-length': '63',
connection: 'close',
'x-frame-options': 'DENY' }

Technical details:

  • sendgrid-nodejs Version: 3.0.4
  • Node.js Version: 4.1.2
@thinkingserious thinkingserious added type: bug bug in the library status: help wanted requesting help from the community labels Jun 15, 2016
@thinkingserious
Copy link
Contributor

@eaparango this is a library problem. I was able to successfully send your email through these examples: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/curl_examples.html

So I'm filing this one as a bug and we will figure out a fix.

@thinkingserious
Copy link
Contributor

OK, I think I've found the fix:
https://github.com/sendgrid/nodejs-http-client/blob/master/lib/client.js#L76
needs to be Buffer.byteLength(body)

@thinkingserious
Copy link
Contributor

The fix is in place in version 3.0.5. I've tested against your code above and it now works.

The issue was in the way I was calculating the content-type length. I did not account for the varying byte lengths of unicode characters.

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

2 participants