1

我正在尝试发送一封简单的电子邮件(在本地,所以我的环境变量没有设置),我得到:Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

这是我的代码

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,
    });
  },

});

我正在从客户端调用 sendInviteEmail (将在服务器上检查它的有效性)并将该数据传递给 sendEmail (这就是我目前有一些冗余的原因)。我的代码基本上来自 docs.meteor.com,所以我想知道为什么这会出现光纤问题。

非常感谢

4

1 回答 1

0

你的代码对我来说很好。我直接复制了你的代码并打电话给

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

从客户端控制台,一切顺利。

我想你可能安装email不正确。如果您从 npm 包运行异步函数,您将收到此错误。要安装email你需要运行的包

meteor add email

我猜你将它添加为 npm 包或其他东西。我希望这有帮助。

如果您对收到的错误感兴趣,那么当我构建一个侦听 postresql 触发器的应用程序时,我遇到了很多相同错误的问题。我使用了来自大气(https://atmospherejs.com/package/postgresql)的 pg 包,但为了让它工作,我需要使用Meteor._wrapAsync. 这是一个例子:

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

// Run connect as usual
pg.wrapped_connect(conParams, function(err, client) {
  ...
});
于 2014-06-10T12:44:33.823 回答