简体   繁体   English

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

[英]Sending email via Mandrill through JSON in javaScript

I'm trying to send a test email by using JSON and java script. 我正在尝试使用JSON和Java脚本发送测试电子邮件。 I registered for a free trial in Mandrill and i got a Testing API key. 我注册了Mandrill的免费试用版,并且获得了Testing API密钥。 I'm calling the sendTheMail function when i press a certain button. 当我按下某个按钮时,我正在调用sendTheMail函数。 When i press the button i know the program is entering the SendtheMail function but nothing is happening. 当我按下按钮时,我知道程序正在进入SendTheMail功能,但是什么也没发生。 Any Help please? 有什么帮助吗?

My code is: 我的代码是:

<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>

Nothing is happening because you declare the function "sendTheMail()", but you are not invoking it. 什么都没有发生,因为您声明了函数“ sendTheMail()”,但是您没有在调用它。

Try this: 尝试这个:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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