Question

I created A little snippet on parse.com from facebook. This snippet is used for sending contact information from web application.

// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:

Parse.Cloud.define("sendMail", function(request, response) {
  var Mandrill = require('mandrill');
  var EJS = require('ejs')

  var params = request.params;
  var data = params.data;

  var html = "<!doctype html>" +
             "<html>" +
               "<head>" +
                 "<meta charset='utf-8'>" +
               "</head>" +
               "<body>" +
                 "<h2>Уведомление с сайта tverkardan.ru!</h2>" +
                 "<h3>Новая заявка</h3>" +
                 "<table>" +
                   "<tr>" +
                     "<td><b>ФИО:</b></td>" +
                     "<td>" + data.name + "</td>" +
                   "</tr>" +
                   "<tr>" +
                     "<td><b>Телефон:</b></td>" +
                     "<td>" + data.phone + "</td>" +
                   "</tr>" +
                   "<tr>" +
                     "<td><b>E-mail:</b></td>" +
                     "<td>" + data.email + "</td>" +
                   "</tr>" +
                   "<tr>" +
                     "<td><b>Сообщение:</b></td>" +
                     "<td>" + data.message + "</td>" +
                   "</tr>" +
                 "</table>" +
               "</body>" +
             "</html>";

  Mandrill.initialize('API-KEY');
  Mandrill.sendEmail({
    message: {
      html: html,
      subject: "Уведомление с сайта tverkardan.ru",
      from_email: "info@tverkardan.ru",
      from_name: "Сайт tverkardan.ru",
      to: [
        {
          email: "mixan946@yandex.ru",
          name: "ТверьКарданСервис"
        }
      ]
    },
    headers: {
      "Content-type": "text/html; charset='UTF-8'"
    },
    async: true
  },{
    success: function(httpResponse) {
      console.log(html);
      console.log(httpResponse);
      response.success("Письмо успешно отправлено!");
    },
    error: function(httpResponse) {
      console.error(httpResponse);
      response.error("Ошибка! Что-то пошло не так!");
    }
  });
});

There is an application call of this snippet:

Parse.Cloud.run("sendMail", {data: {name: "test", phone: "123123123", email: "email@eamil.ru", message: "фываыфва ыфва фыва ывф"}})

All code works fine but when I receive this email. There is no cyrillic symbols

email

I made some research and find that API calls in Mandrill doesn't receive cyrillic symbols too

API call params

Was it helpful?

Solution

you need to encode text to UTF-8 like this: for raw text something along those lines should be enough:

function encode_utf8(s) {
    return unescape(encodeURIComponent(s));
}
...
text="Ты читала "+title+" от "+author+" еще "+readingSessionTime/60.0+" минут или "+readingSessionTime/3600.0+" часов"


    console.log("Sending:"+text);
    //TODO:use user's e-mail field (and check for e-mail to exist)
    Mandrill.sendEmail({
        message: {
            text: encode_utf8(text),e
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top