Reputation: 3
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": "[email protected]",
"from_name": "test",
"to":[{"email": "[email protected], "name": "myname"}],
"subject": "subj",
"text": "msg"
}
});
}
</script>
Upvotes: 0
Views: 245
Reputation: 2022
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": "[email protected]",
"from_name": "test",
"to":[{"email": "[email protected], "name": "myname"}],
"subject": "subj",
"text": "msg"
}
});
}
// Here you are calling the function to be executed
sendTheMail();
</script>
Upvotes: 2