title: mailgun not sending email returning undefined data
body: <p>I am trying to implement a simple email confirmation on signup flow using Angular 4, nodejs, mailgun-js and mailgun. The problem is the mailgun send: </p>
  
  <pre><code>mailgun.messages().send(data, function(error, body) {
          console.log(body);
      });
  </code></pre>
  
  <p>is timing out with the following error on the front-end:</p>
  
  <pre><code>POST http://localhost:3000/users/sendMail net::ERR_EMPTY_RESPONSE
  core.js:1448 ERROR 
  HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
  error
  :
  ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: "error", …}
  headers
  :
  HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}
  message
  :
  "Http failure response for (unknown url): 0 Unknown Error"
  name
  :
  "HttpErrorResponse"
  ok
  :
  false
  status
  :
  0
  statusText
  :
  "Unknown Error"
  url
  :
  null
  __proto__
  :
  HttpResponseBase
  </code></pre>
  
  <p>The back-end show now errors but the return value (body) is undefined and the email is not sent. This is my complete back-end sendMail module:</p>
  
  <pre><code>const api_key = '&lt;key-f40360259dea7c667ca06d4aee956421&gt;';
  const DOMAIN = '&lt;sandbox836cdf3cfe9c467b916fe5bb0d73e7e7.mailgun.org&gt;';
  const mailgun = require('mailgun-js')({ apiKey: api_key, domain: DOMAIN });
  // ---------------- sendMail variables -----
  
  router.post('/sendMail', (req, res, next) =&gt; {
  
      console.log("Email message data: " + JSON.stringify(req.body));
  
      const data = {
          from: 'xxxxdev@gmail.com',
          to: [req.body.email, 'xxxxxxx@gmail.com'],
          name: req.body.firstName,
          code: req.body.workshopCode,
          subject: req.body.workshopTitle,
          text: req.body.messageBody
      };
  
      mailgun.messages().send(data, function(error, body) {
          console.log(body);
      });
  });
  </code></pre>
  
  <p>Both From and To email are valid email address and the req.body displayed in the console.log is the correct data passed from the Front-End.</p>
  
  <p>This the Front-end sendmail module:</p>
  
  <pre><code> sendEmailConfirmation(message) {
       const headers = new HttpHeaders();
       headers.append('Content-Type', 'application/x-www-form-urlencoded');
  
       this.http.post('http://localhost:3000/users/sendMail', message).subscribe((data) =&gt; {
            console.log('Mail return data: ' + data);   &gt;&gt;&gt;THIS LINE IS NEVER EXECUTED&lt;&lt;&lt;&lt;&lt;&lt;
                },
          );
    }
  </code></pre>
  
  <p>What am I missing here??.....</p>
  
  <p>I noticed the absence of a res.send so I added the following: </p>
  
  <pre><code>if (error) throw error;
          else {
              res.send('Email sent');
          }
  </code></pre>
  
  <p>Now I get a forbidden error on the back-end:</p>
  
  <pre><code>(node:10780) UnhandledPromiseRejectionWarning: Error: Forbidden
      at IncomingMessage.res.on (C:\connect2Server\node_modules\mailgun-js\lib\request.js:301:17)
      at IncomingMessage.emit (events.js:165:20)
      at endReadableNT (_stream_readable.js:1101:12)
      at process._tickCallback (internal/process/next_tick.js:152:19)
  (node:10780) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a ca
  tch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
  </code></pre>