通过Mandrill在javaScript中通过JSON发送电子邮件

时间:2016-11-20 10:57:26

标签: javascript json mandrill

我尝试使用JSON和java脚本发送测试电子邮件。我在Mandrill注册了免费试用版,并获得了测试API密钥。当我按下某个按钮时,我正在调用sendTheMail函数。当我按下按钮时,我知道程序正在进入SendtheMail功能但没有任何事情发生。请帮忙吗?

我的代码是:

<script type="text/javascript" src="mandrill.min.js"></script>
<script>

var m = new mandrill.Mandrill('xxx-xxxMy testing API key')

 function sendTheMail() {
  m.messages.send({
  "message": {
  "from_email": "myemail@myemail.com",
  "from_name": "test",
  "to":[{"email": "myemail@myemail.com, "name": "myname"}],
  "subject": "subj",
  "text": "msg" 
  }
});
}

</script>

1 个答案:

答案 0 :(得分:1)

因为您声明了函数“sendTheMail()”而没有发生任何事情,但您没有调用它。

试试这个:

<script type="text/javascript" src="mandrill.min.js"></script>
<script>
    var m = new mandrill.Mandrill('xxx-xxxMy testing API key');

    function sendTheMail() {
      // Log to console that you are sending the email.
      // optional to show that the function are called                   
      console.log("sending email...");

      m.messages.send({
          "message": {
              "from_email": "myemail@myemail.com",
              "from_name": "test",
              "to":[{"email": "myemail@myemail.com, "name": "myname"}],
              "subject": "subj",
              "text": "msg" 
           }
      });
    }

    // Here you are calling the function to be executed
    sendTheMail();

</script>