简体   繁体   中英

Setting up Sendinblue mail service with Google Apps Script

I am trying to set up Sendinblue's mail service with Google Apps Script as follows:

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);});

}

Error message: ReferenceError: "require" is not defined.

The sendinblue node.js library talks about a Restler library also being required, but I'm really not sure how to incorporate this library also? I am a novice so could be completely off-track here.

Any guidance is appreciated.

Documentation:

https://apidocs.sendinblue.com/tutorial-sending-transactional-email/

https://github.com/mailin-api/mailin-api-node-js/tree/master/V2.0

The code to send an email using the Sendinblue's mail service should probably look something like this:

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())
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM