3

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

4

1 回答 1

4

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())
}
于 2017-10-05T16:06:17.363 回答