【问题标题】:Meteor Fiber Email流星光纤电子邮件
【发布时间】:2014-07-30 05:30:15
【问题描述】:

我正在尝试发送一封简单的电子邮件(在本地,所以我的环境变量没有设置),我收到: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,所以我想知道为什么这会出现纤维问题。

非常感谢

【问题讨论】:

  • 您从客户端调用方法sendInviteEmail,而不是sendEmail

标签: javascript email meteor node-fibers


【解决方案1】:

您的代码对我来说很好用。我直接复制了你的代码并调用了

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

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

我认为您可能错误地安装了email。如果您从 npm 包运行异步函数,您将收到此错误。要安装 email 包,您需要运行

meteor add email

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

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

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

// Run connect as usual
pg.wrapped_connect(conParams, function(err, client) {
  ...
});

【讨论】:

  • 感谢您试用!我实际上了解到,如果我设置了我的电子邮件环境变量并实际发送了电子邮件(而不是看着控制台“发送”它),它就可以工作。我的控制台肯定有些时髦,但仅适用于这个应用程序。我在另一个应用程序中使用了电子邮件包,它运行良好。再次感谢您的帮助!
猜你喜欢
  • 2013-12-05
  • 1970-01-01
  • 1970-01-01
  • 2013-10-04
  • 2020-03-09
  • 2012-12-01
  • 2016-05-10
  • 2016-11-04
  • 2023-04-05
相关资源
最近更新 更多