1

I recently started to use Mandrill for client e-mail sending. The client's website doesn't use any server side program, so every logic must be on client side.

What I have now is working in Chrome, FireFox, IE10, but not in LTE IE9 nor Android < 4.0 neither IOS :\

m = new mandrill.Mandrill("APIKEY", true)
m.call "messages/send", {
    message:
        html: createHtml()
        subject: "subj"
        from_email: "sender@example.dk",
        from_name: "From",
        to: [
            email: "user@example.com"
            name: "User"
        ]
}, (()->
    console.log "success"
    @
), ()->
    console.log "error"
    @

In this code, I'm using the JS Mandrill API wrapper, but I tried it with jQuery ajax POST-ing and I've got the same result.

jQuery version:

$.ajax
    type: "POST"
    url: "https://mandrillapp.com/api/1.0/messages/send.json"
    data:
        key: "APIKEY"
        message:
            html: createHtml()
            subject: "subject"
            from_email: "sender@example.dk",
            from_name: "From",
            to: [
                email: "user@example.com"
                name: "User"
            ]

Can anyone help me out, how to fix cross-domain API calling to Mandrill?

seniorpreacher
  • 666
  • 2
  • 11
  • 31

1 Answers1

3

Your code seems valid, so probably you've run into a browser compatibility issue.

The Mandrill API wrapper is using native XMLHttpRequest under the hood so it may be incompatible with older browsers. If you need to support IE<9 you will nedd a 1.x version of jQuery - all 2.x versions don't support legacy browsers anymore (see http://jquery.com/browser-support/).

I posted a working example on JSBin: http://jsbin.com/UyehELo/2/edit. Tested only iOS because unfortunately I have no access to IE or Android. The example allows you to see the API response also on mobile devices with no easy access to the console.

PS. Remember that using mandrill on client-side is usually not the best idea as you expose your API key publicly so anyone can take it and send emails on your behalf.

lukaszfiszer
  • 2,591
  • 1
  • 19
  • 13
  • Thanks, I will check it later when I get home :) Btw. I use jQuery 1.10.2, so that should not be a problem. And with Mandrill, you can specify IPs where you want to allow e-mail sending, so "hackers" can only use it from the same site – seniorpreacher Oct 09 '13 at 11:34