joedawson's avatar

Mailgun & Vue?

Hello everyone,

I'm nearing the end of building a static website (using Jigsaw and have used some Vue.

I'm trying to use the bojand/mailgun-js node package and I'm not 100% sure on how to use it with Vue. At the moment, when my form is submitted I have it set up to fire the following method.

submit: function() {

    var mailgun = require('mailgun-js')({
        apiKey: 'key-XXXXXXXXXX',
        domain: 'smtp.mailgun.org'
    });

    var data = {
        from:       this.message.name + ' <'+ this.message.email +'>',
        to:         '[email protected]',
        subject:    'Message Received',
        text:       this.message.body
    };

    mailgun.messages().send(data, function (error, body) {
        console.log(body);
    });
}

I've basically copied and pasted the documentation and obviously tweaked some values based on the data my form receives.

When I submit the form, I get the following message in the console:

app.js:488 Uncaught TypeError: Invalid Version:

Then without changing anything, if I submit it again I get this:

app.js:99211 Uncaught TypeError: require(...) is not a function

Has anyone used this package before? If yes, any ideas how I can get this working?

0 likes
3 replies
joedawson's avatar

Haven't had much luck with this. Anyone else managed to send emails via Mailgun with just Vue? I've tried a few packages, none of which I was able to successfully get an email sent with.

HRcc's avatar
HRcc
Best Answer
Level 22

If the packages don't work, there might be some inconsistence with the Mailgun's API, however you should always be able to use their API directly. Just build a wrapper class around your HTTP client (probably vue-resource) and you will get a nice interface in no time.

joedawson's avatar

Was hoping there might be an easier way to do this using one of the packages instead of reinventing the wheel. I'll look at just using vue-resource then to make a request. Thanks @HRcc :)

Please or to participate in this conversation.