javascript - 使用 Google Apps 脚本设置 Sendinblue 邮件服务

标签 javascript node.js google-apps-script sendinblue

我正在尝试使用 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:“require”未定义。

sentinblue 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":"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())
}

关于javascript - 使用 Google Apps 脚本设置 Sendinblue 邮件服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46583743/

相关文章:

json - 大型 JSON 数据未显示在控制台中

google-apps-script - 如何计算Google表格文档中的公式数量?

javascript - 有没有办法将 Google 电子表格保存为数据库中的 blob,然后在应用程序脚本期间将该 blob 作为电子表格打开

javascript - 通过侧边栏中显示的按钮向 Google 表格中的单元格添加值

javascript - JS 原型(prototype)是否可以访问初始化期间传递给对象的参数?

javascript - 如何在 Appgyver Steroids 中创建自定义 webview

javascript - 将焦点绑定(bind)到单选按钮

javascript - 检测移动和桌面设备上的字符代码

node.js 模块或 require.js

node.js - babel-node 无法识别 jsx <