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 protected]", "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
Your code works fine for me. I copied your code straight up and called
Meteor.call("sendInviteEmail", "[email protected]")
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) {
...
});