node.js - 带有nodejs的附件SendinBlue Api
问题描述
我想将 Sendinblue api 与我的 lb4 应用程序一起使用来发送邮件,但我在附件中遇到了一些困难,我可以获得一个干净的例子来链接 sendinblue api V3 和 loopback4(nodejs)谢谢
解决方案
我按照他们的参考文档中提到的步骤,使下面的脚本工作!
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,然后按照他们的参考文档传递。
如果有帮助,请告诉我!谢谢
推荐阅读
- python - 无法使用scrapy中的列表理解获取某些链接
- java - 如何在 IntelliJ 社区版中为 Maven 项目创建战争文件?
- python - 在python中不使用除法创建除法程序
- docker-compose - JHipster/微服务前端开发热重载
- javascript - 按下tab键时如何选择mat选项?,它应该像mat-autocomplete angular 6中的输入按钮一样工作
- javascript - Infogram 嵌入代码未在 React 中呈现
- javascript - 使用 JavaScript (VueJS) 的粘性元素
- c# - 替代输出变量
- python - 文件名与 Python 正则表达式匹配
- angular - 在前端禁用角度 6 的输入场