简体   繁体   中英

Sending email via Mandrill through JSON in javaScript

I'm trying to send a test email by using JSON and java script. I registered for a free trial in Mandrill and i got a Testing API key. I'm calling the sendTheMail function when i press a certain button. When i press the button i know the program is entering the SendtheMail function but nothing is happening. 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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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