Parse Cloud - 带模板的 Sendgrid
Posted
技术标签:
【中文标题】Parse Cloud - 带模板的 Sendgrid【英文标题】:Parse Cloud - Sendgrid with Template 【发布时间】:2017-10-01 19:44:45 【问题描述】:有人可以将 SendGrid 模板与 Parse Cloud Code 一起使用吗?
这可行,但只发送文本,关于如何使用 template_id 的任何想法?
我尝试使用过滤器但没有成功。
Parse.Cloud.define("sendEmail", function(request, response)
// Import SendGrid module and call with your SendGrid API Key
var sg = require('sendgrid')('your SendGrid API key here');
// Create the SendGrid Request
var reqSG = sg.emptyRequest(
method: 'POST',
path: '/v3/mail/send',
body:
personalizations: [
to: [
// This field is the "to" in the email
email: request.params.toEmail,
,
],
// This field is the "subject" in the email
subject: request.params.subject,
,
],
// This field contains the "from" information
from:
email: 'info@youremail.com',
name: 'Your Name',
,
// This contains info about the "reply-to"
// Note that the "reply-to" may be different than the "from"
reply_to:
email: 'info@youremail.com',
name: 'Your Name',
,
content: [
type: 'text/plain',
value: request.params.body,
,
],
,
);
sg.API(reqSG, function(SGerror, SGresponse)
// Testing if some error occurred
if (SGerror)
// Ops, something went wrong
console.error('Error response received');
console.error('StatusCode=' + SGresponse.statusCode);
console.error(JSON.stringify(SGresponse.body));
response.error('Error = ' + JSON.stringify(SGresponse.body));
else
// Everything went fine
console.log('Email sent!');
response.success('Email sent!');
);
);
这是来自 Back4App https://docs.back4app.com/docs/integrations/using-sendgrid-to-send-email/ 上的文档
【问题讨论】:
【参考方案1】:如果有人在寻找答案,结果很简单,
将 template_id 添加为个性化并将消息类型更改为 text/html,
template_id:"your template_id",
content: [
type: 'text/html',
// This field is the body of the email
value: "",
,
],
【讨论】:
以上是关于Parse Cloud - 带模板的 Sendgrid的主要内容,如果未能解决你的问题,请参考以下文章
在 Parse.Cloud 代码中调用 Parse.Query 时无法找到对象
Parse.Cloud.httpRequest 使用 POST 方法返回“未定义”而不是响应