mailgun / mailgun-js-boland

A simple Node.js helper module for Mailgun API.
http://bojand.github.io/mailgun-js
MIT License
894 stars 122 forks source link

Sending not working in Zeit Now 2.0 lambda #233

Closed alexpricedev closed 5 years ago

alexpricedev commented 5 years ago

1) What version of the module is the issue happening on? Does the issue happen on latest version? 0.22.0

2) What platform and Node.js version? (For example Node.js 6.9.1 on Mac OS X) I'm using Now 2.0 (by Zeit). Think it's 8.x from what I can find on chat.

3) Does the action work when you manually perform request against mailgun using curl (or other means)? Yes

4) Sample source code or steps to reproduce

const { send, json } = require('micro');
const mailgun = require('mailgun-js')({
  apiKey: process.env.MAILGUN_API_KEY,
  domain: '', // removed
});

const post = require('./post');

module.exports = post(async (req, res) => {
  try {
    const data = await json(req);

    const email = {
      from: '', // removed
      to: '', // removed
      subject: 'Signup',
      text: `${data.firstName} ${data.lastName} (${
        data.email
      }) signed up.`,
    };

    // Only send the email in production
    if (process.env.NODE_ENV === 'production') {
      mailgun.messages().send(email);
    }
    console.log('Sending email...', email);
  } catch (error) {
    console.log('error', error);
  }
  send(res, 200);
});

This is pretty much the whole lambda.

(Write description of your issue here, stack traces from errors and code that reproduces the issue are helpful) It works like a charm on local (running through micro-dev) but when it's running in prod .send(email) seems to do nothing! I know it's getting hit from different log statement tests.

Could it be a host or proxy issue?

arnars commented 5 years ago

@remotealex Is this still an issue? Considering using this library for a now.sh 2.0 app.

alexpricedev commented 5 years ago

@anrars yeah, I haven't looked into it because it's a non-crucial email. Perhaps I'll dig into this today. There are some other pretty solid node mailgun wrappers so maybe try one of those..?

alexpricedev commented 5 years ago

@arnars I've just tried again with another package (mailgun-es6) and it still doesn't work.. I guess this isn't an issue with the package so I'll close it. To follow the convo please see the spectrum thread I've started: https://spectrum.chat/zeit/now/mailgun-emails-not-sending-on-now-2-lambda~222c6183-fe18-4acd-964f-d4bc9d2ef398

alexpricedev commented 5 years ago

Just incase that chat gets archived or lost, the solution was that I missed an await (or other promise handler) on my send call!! The lambda was executing and then closing before the request could complete. Making it sync did the trick :)