title: sending email through mailgun
body: <p>I am trying to add a mailgun contact form to my website using nodejs express and mailgun-js. But somehow I cannot get it to work. My api key and domain are good since I tested them with the sample code on mailgun-js's official github page. So I am wondering if there is anything wrong with the following pieces of code. (routing and everything else works perfectly)</p>
  
  <p>./models/mailer.js</p>
  
  <pre><code>            var api_key = 'xxxxxxx';
              var domain = 'xxxxxxxx';
  
              var Mailgun = require('mailgun-js');
  
              exports.sendOne = function (locals,callback) {
  
                  console.log(locals);
                  var mailgun = new Mailgun({apiKey: api_key,domain:domain});
  
                  var data = {
                from: 'xxxxxx',
                to: 'myemail@hotmail.com',
                subject: 'Hello World',
                text: 'Testing some Mailgun awesomness!'
              };
  
                  mailgun.message().send(data,function (err,body) {
                          if(err) return callback(err);
                          console.log('message sent');
                          callback(null,body);
                  });
              };
  </code></pre>
  
  <p>./controllers/contactCtrl.js</p>
  
  <pre><code>    var mailer = require('../models/mailer');
  
      exports.contact = function (req,res,next) {
          res.render('contact');
      };
  
  
      exports.receiveMessage = function (req,res,next) {
  
              mailer.sendOne(req.body,function (err,body) {
                  if(err) return next(err);
                  console.log(body);
                  res.send({message:'Your message has been successfully sent'});
              });
  
      };
  </code></pre>
  
  <p>Thanks A Lot   :)</p>