Mandrill 解析 facebook 编码问题
Posted
技术标签:
【中文标题】Mandrill 解析 facebook 编码问题【英文标题】:Mandrill parse facebook encoding issue 【发布时间】:2014-06-28 20:51:07 【问题描述】:我从 facebook 在 parse.com 上创建了 A little sn-p。此 sn-p 用于从 Web 应用程序发送联系信息。
// 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("Ошибка! Что-то пошло не так!");
);
);
有这个sn-p的应用调用:
Parse.Cloud.run("sendMail", data: name: "test", phone: "123123123", email: "email@eamil.ru", message: "фываыфва ыфва фыва ывф")
所有代码都可以正常工作,但是当我收到这封电子邮件时。没有西里尔符号
我做了一些研究,发现 Mandrill 中的 API 调用也不接收西里尔符号
API call params
【问题讨论】:
【参考方案1】:您需要将文本编码为 UTF-8,如下所示: 对于原始文本,这些内容应该足够了:
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
【讨论】:
以上是关于Mandrill 解析 facebook 编码问题的主要内容,如果未能解决你的问题,请参考以下文章
尝试从 Mandrill 发送电子邮件时出现 html 或车把编码问题