这些是我要参考的文件:
https://www.smtp.com/developers/smtp-api/
这是他们提供的PHP示例:
https://api.smtp.com/doc/PhpExample.html
这是到目前为止我尝试过的-我已验证我的配置导出正确并且API密钥正确。我已经用示例数据替换了代码中的一些内容,以使电子邮件保持不接触互联网。
const rp = require("request-promise");
const moment = require("moment");
const config = require("../../config/smtp");
exports.notify = function(project, note) {
var options = {
method: "POST",
uri: config.uri,
headers: {
"content-type": "application/json"
},
body: {
recipients: {
to: [
{
name: "The Recipient",
address: "email@email.com"
}
]
},
originator: {
from: {
name: "Recipient's Notification System",
address: "notifications@email.com"
},
reply_to: {
name: "Do Not Reply",
address: "donotreply@email.com"
}
},
custom_headers: {},
subject:
"New note on Job " +
project._projectid +
" | " +
project.location.line1,
body: {
parts: [
{
type: "text/html",
charset: "UTF-8",
content:
"The following note was left on Project " +
project._projectid +
":\n\n" +
note.content +
"\n\n" +
"Author: " +
note.meta.author.name +
"at " +
moment(note.meta.created).format("MM/DD/YYYY hh:MMa")
}
],
attachments: []
}
},
json: true // Automatically stringifies the body to JSON
};
rp(options)
.then(res => {
console.log(res);
})
.catch(err => {
console.error(err);
});
};