我使用claudiajs apibuilder来开发一些REST API。我想在这个api中使用pepipost email api来发送事务性电子邮件。在测试期间,api在我的lambda函数之外工作得很好。当我在lambda中包含epi时,它们会停止工作,并且不会抛出任何错误。
是否有要设置的权限?或者调用外部api所需的其他设置?
我试着清理函数,只留下邮件发送,以便更好地调试它
这是测试结束
api.post('/users/test', function(request) {
return new Promise((resolve, reject) => {
let eTo = "email@email.com",
eSubject = 'Activate your account',
eAttributes = {
THE_NAME : "userData.name",
THE_ACTIVATION_URL : "config.activationUrl"+"/123456",
THE_ACTIVATION_LINK : "config.activationLink",
THE_ACTIVATION_CODE : "aToken"
},
eType = 'eTActivationEN',
eTags = 'activation';
sendemail( eTo, eSubject, eAttributes, eType, eTags );
resolve( { "success" : "works" } );
});
},{ success : { code : 200}, error : { code : 401 } });这是发送电子邮件的模块:
var http = require("https");
var e = require('./../config.json');
module.exports.send = ( eTo, eSubject, eAttributes, eType, eTags ) => {
return new Promise( (resolve, reject) => {
var options = {
"method": "POST",
"hostname": "api.pepipost.com",
"port": null,
"path": "/v2/sendEmail",
"headers": {
"content-type": "application/json",
"api_key": e.ePepipostToken
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
output = body.toString();
resolve ( output );
});
});
req.write(JSON.stringify({
personalizations: [
{
recipient: eTo,
attributes: eAttributes
}
],
from: { fromEmail: e.eFromAddress, fromName: e.eFromName },
subject: eSubject,
templateId: 18924,
tags: eTags,
content: "content" }));
req.end();
}) // end Promise
}同样的模块在lambda外工作得很好,但在内部却不能工作。当我尝试呼叫端点时,我收到了{"success“:"works"},但没有电子邮件。并且在cloudwatch控制台上没有错误。
发布于 2019-04-23 21:17:16
更新:
如果我包含所有的发送电子邮件代码,它可以工作:
api.post('/users/test2', function(request) {
return new Promise((resolve, reject) => {
var http = require("https");
var options = {
"method": "POST",
"hostname": "api.pepipost.com",
"port": null,
"path": "/v2/sendEmail",
"headers": {
"content-type": "application/json",
"api_key": config.ePepipostToken
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
output = body.toString();
resolve ( output );
});
});
eAttributes = {
THE_NAME : "userData.name",
THE_ACTIVATION_URL : "config.activationUrl"+"/123456",
THE_ACTIVATION_LINK : "config.activationLink",
THE_ACTIVATION_CODE : "aToken"
}
req.write(JSON.stringify({
personalizations: [
{
recipient: "email@email.com",
attributes: eAttributes
}
],
from: { fromEmail: "devm425tj@pepisandbox.com", fromName: "me" },
subject: "eSubject",
templateId: 18924,
tags: "activation",
content: "content" }));
req.end();
});
},{ success : { code : 200}, error : { code : 401 } });问题是我不能在我需要发送的每封电子邮件中都包含相同的代码。我需要让它从外部模块工作。
发布于 2019-04-23 21:43:37
第二次更新:代码运行良好,问题出在caludiajs apibuilder中,我无法从api.post("something")块调用外部函数,我将尝试理解如何..
https://stackoverflow.com/questions/55811721
复制相似问题