我正在尝试使用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" : {"[email protected]":"to whom!"},
"from" : ["[email protected]", "from email!"],
"subject" : "My subject",
"html" : "This is the <h1>HTML</h1>"
}
client.send_email(data).on('complete',function(data){console.log(data);});
}
错误消息: ReferenceError:未定义“要求”。
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
最佳答案
使用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":"[email protected]"},
"htmlContent":"this is the body",
"subject":"subject",
"replyTo":{"email":"[email protected]","name":"Name"},
"to":[{"email":"[email protected]","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())
}