在Google Apps脚本中使用Mandrill API [英] Use Mandrill API in Google Apps Script

查看:114
本文介绍了在Google Apps脚本中使用Mandrill API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的谷歌应用程序脚本中使用mandrill电子邮件发送api。在谷歌脚本中,我必须使用JSON代码,但我没有得到我将如何使用它。

I want to use mandrill email sending api in my google apps script. In google script I have to use JSON code but I am not getting how I will use it. I am very new in Google apps script.

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脚本中使用此代码。

I am not getting how to use this code in Google Apps Script.

推荐答案

您需要使用urlfetchapp。

You'd need to use the 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);

没有测试过这个代码,但应该是这样的。

Haven't tested this code, but should be something like that.

这篇关于在Google Apps脚本中使用Mandrill API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆