0

Google Apps スクリプトで mandrill メール送信 API を使用したいと考えています。Google スクリプトでは、JSON コードを使用する必要がありますが、その使用方法がわかりません。私は Google アプリ スクリプトの初心者です。

var m = new mandrill.Mandrill('XXXXXXXXXXX');
var from_email = "user4@gmail.com";
var to = '[
{
  "email": "recipient.email@example.com",
    "name": "Recipient Name"
}
],';

// create a variable for the API call parameters
var params = {
  "message": {
    "from_email":from_email,
    "to":[{"email":to}],
    "subject": "Sending a text email from the Mandrill API",
    "text": "I'm learning the Mandrill API at Codecademy, it's very difficult."
  }
};

function sendTheMail() {
  // Send the email!
  alert('this is a mail script');
  m.messages.send(params, function(res) {
    log(res);
  }, function(err) {
    log(err);
  });
}

Google Apps Script でこのコードを使用する方法がわかりません。

4

2 に答える 2

2

urlfetchapp を使用する必要があります。

var url = "https://mandrillapp.com/api/1.0/messages/send.json";
var your_key = "xxxxxxxxxxxxx";
var from_email = "user4@gmail.com";
var to = [{
    "email": "recipient.email@example.com",
    "name": "Recipient Name"
}];

var params = {
    "key": your_key,
    "message": {
        "from_email":from_email,
        "to":[{"email":to}],
        "subject": "Sending a text email from the Mandrill API",
        "text": "I'm learning the Mandrill API at Codecademy, it's very difficult."
    }
};

var payload = JSON.stringify(params);

var options = {
    'method': 'post',
    'payload': payload,
    'contentType' : 'application/json'
};

var response = UrlFetchApp.fetch(url, options);

このコードはテストしていませんが、そのようなものになるはずです。

于 2013-10-14T10:09:32.777 に答える