elbuo8 / sendgrid-parse

SendGrid Parse Cloud Module
9 stars 3 forks source link

Add Pdf File with Special characters (Spanish/Portuguese) #6

Open nathyecomp opened 8 years ago

nathyecomp commented 8 years ago

I've been creating a PDF file (with special characters: é, ê, á, ç, ...) by using jsPDF and saving them as a Parse File. Then, in Parse Cloud, I retrieve this parse file and send it as an attachment by using sendgrid.

I checked the files in my Parse basedata and the pdf document is great, with all portuguese characters.
However, the document that I receive in my email is not the same (the special characters are comming such as "?.?;"). So, I concluded that the problem is occurring during the process of sengdrig attachment. Anyone can help me? If it does not function, I will need to change all my solution =( =(

I tried to change the Parse.http header of sendgrid.js by adding "charset=UTF-8" (as follows), but it not solved my problem.. "Parse.Cloud.httpRequest({ method: options.method, headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},"

dchekanov commented 8 years ago

This module reads file content and transforms it into an UTF-8 encoded string (https://github.com/elbuo8/sendgrid-parse/blob/master/sendgrid.js#L212, https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end). This is done because Parse.Cloud.httpRequest can not make multipart/form-data requests to send binary data to SendGrid.

Since PDF is a binary file format (it can have embedded images, for example), transforming the file into a string that way messes up its contents.

If you want to send binary files as attachments, you'd need to switch to a service that can receive files as Base64-encoded strings. SendGrid doesn't seem to have this feature (I haven't heard anything from their support in 5 days), neither does Mailgun (which support guys are great). Mandrill does, but it's not free anymore, and I don't know if Parse's module works fine or not. I saw a few free services that recognize Base64-encoded attachments, but you'll need to write your own module for Parse to communicate with those.

The easy solution would be to just put a link to the file in the email.

m1gu3l commented 8 years ago

You need to send data to SendGrid API as multipart/form-data instead of x-www-form-urlencoded. See https://github.com/m1gu3l/parse-sendgrid-mailer/