0

我想将 Sendinblue api 与我的 lb4 应用程序一起使用来发送邮件,但我在附件中遇到了一些困难,我可以获得一个干净的例子来链接 sendinblue api V3 和 loopback4(nodejs)谢谢

4

1 回答 1

0

我按照他们的参考文档中提到的步骤,使下面的脚本工作!

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.sendinblue.com/v3/smtp/email',
  headers: {
    accept: 'application/json',
    'content-type': 'application/json',
    'api-key': 'API-KEY'
  },
  body: {
    sender: {name: 'Your Name', email: 'youremail@gmail.com'},
    to: [{email: 'recipient@gmail.com', name: 'Recipient name'}],
    attachment: [
      {
        url: 'http://personal.psu.edu/xqz5228/jpg.jpg', // Should be publicly available and shouldn't be a local file
        name: 'myAttachment.jpg'
      }
    ],
    htmlContent: 'This is a test Content',
    subject: 'This is test Subject'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

尽管您还没有说明附件所面临的确切问题,但我认为这可能与附件 url 不是绝对 url 而是本地文件有关。如果这是问题所在,那么我建议您将附件转换为 base64,然后按照他们的参考文档传递。

如果有帮助,请告诉我!谢谢

于 2020-08-24T18:40:33.523 回答