1

I'm attempting to send a simple email (locally, so my environment variables aren't set), and I get: Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

Here's my code

Meteor.methods({

  sendInviteEmail: function(emails) {
    console.log("[sendInviteEmails], ", emails);
      if (emails !== void 0) {
        console.log("[sendInviteEmails] calling meteor method: sendEmail");
        return Meteor.call("sendEmail", emails, "email@gmail.com", "test", "test");
      }
  },

  sendEmail: function(to, from, subject, text) {
    this.unblock();
    Email.send({
      to: to,
      from: from,
      subject: subject,
      text: text,
    });
  },

});

I'm on calling sendInviteEmail (will be checking it for validaty on the server) from the client and passing that data to sendEmail (which is why i have a bit of redudancy currently). My code is basically from docs.meteor.com, so I'm wondering why this would present a fiber issue.

Thanks much

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Alex_Faber
  • 117
  • 1
  • 8

1 Answers1

0

Your code works fine for me. I copied your code straight up and called

Meteor.call("sendInviteEmail", "my.email@mydomain.com")

from the client console and all went fine.

I think you might have installed email incorrectly. You will get this error if you run async functions from an npm package. To install the email package you need to run

meteor add email

I am guessing you added it as an npm package or something. I hope this helps.

If you are interested in the error you get I had a lot of problems with the same error when I built an app that listened on a postresql trigger. I used the pg package from atmosphere (https://atmospherejs.com/package/postgresql) but to get it working I needed to wrap the functions in Meteor's environment using Meteor._wrapAsync. Here is an example:

// Wrap connect function
pg.wrapped_connect = Meteor._wrapAsync(pg.connect.bind(pg));

// Run connect as usual
pg.wrapped_connect(conParams, function(err, client) {
  ...
});
while
  • 3,602
  • 4
  • 33
  • 42
  • Thanks for trying this out! I actually learned that if I setup my email environment variable and actually sent the email (instead of watching the console "send" it), it worked. Something is definitely funky with my console, but for this app only. I've used the email packages in another app and it worked fine. Thanks again for your help! – Alex_Faber Jun 10 '14 at 15:48