我正在尝试使用Google Apps脚本设置Sendinblue的邮件服务,如下所示:
code.gs
function sendInBlue(){
eval(UrlFetchApp.fetch('https://cdn.rawgit.com/mailin-api/mailin-api-node-js/master/V2.0/mailin.js').getContentText());
var client = new Mailin("https://api.sendinblue.com/v2.0","your access key");
data = {
"to" : {"to@example.net":"to whom!"},
"from" : ["from@email.com", "from email!"],
"subject" : "My subject",
"html" : "This is the <h1>HTML</h1>"
}
client.send_email(data).on('complete',function(data){console.log(data);});
}
错误消息: ReferenceError:&#34;要求&#34;没有定义。
sendinblue node.js库谈到了一个Restler库也是必需的,但是我真的不确定如何合并这个库呢? 我是新手所以可能完全偏离这里。
感谢任何指导。
文档:
https://apidocs.sendinblue.com/tutorial-sending-transactional-email/
https://github.com/mailin-api/mailin-api-node-js/tree/master/V2.0
答案 0 :(得分:2)
使用Sendinblue的邮件服务发送电子邮件的代码应该如下所示:
function sendEmailWithSendInBlue() {
var url = "https://api.sendinblue.com/v3/smtp/email";
var myAccessKey = "[enter your v3 access key]"
var data = {
"sender":{"name":"Name","email":"name@domain.com"},
"htmlContent":"this is the body",
"subject":"subject",
"replyTo":{"email":"name@domain.com","name":"Name"},
"to":[{"email":"name@domain.com","name":"Name"}]
}
var options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(data),
'headers': {'api-key':myAccessKey},
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getResponseCode())
}