Meteor电子邮件未定义,但是从服务器目录中的Meteor.methods运行

时间:2016-07-21 19:13:20

标签: email meteor methods

我在服务器目录中设置了以下Meteor方法:

// Defined in collections/collections.js
Meteor.methods({
    sendEmail: function(options) {
        this.unblock();
        Email.send(options);
    }
});

我称之为:

// Defined in client/main.js
Meteor.call('sendEmail', {
    to: 'yeahright@noneya.com', from: 'yeahright@noneya.com',
    text: 'testing testing'
});

我在运行Meteor的服务器shell中遇到一个错误:

Exception while invoking method 'sendEmail' { stack: 'ReferenceError: Email is not defined\n    at [object
     

对象] .Meteor.methods.sendEmail   (app / server / methods / reservations.js:82:4)\ n在[object   对象] .methodMap。(匿名函数)   (packages / meteorhacks_kadira / lib / hijack / wrap_session.js:164:1)\ n at   maybeAuditArgumentChecks   (packages / ddp-server / livedata_server.js:1711:12)\ n at   packages / ddp-server / livedata_server.js:711:19 \ n at [object   Object] ._。extend.withValue(packages / meteor / dynamics_nodejs.js:56:1)\ n   at packages / ddp-server / livedata_server.js:709:40 \ n at [object   Object] ._。extend.withValue(packages / meteor / dynamics_nodejs.js:56:1)\ n   在packages / ddp-server / livedata_server.js:707:46 \ n在tryCallTwo   (/Users/sltwtr/.meteor/packages/promise/.0.7.3.1y6b71x++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:45:5)\n   在doResolve   (/Users/sltwtr/.meteor/packages/promise/.0.7.3.1y6b71x++os+web.browser+web.cordova/npm/node_modules/promise/lib/core.js:200:13)' ,I20160721-11:50:31.471(-7)?   来源:'方法' }

我已使用

添加了电子邮件包
  

meteor add email

发生了什么?问题包括this onethis one

1 个答案:

答案 0 :(得分:0)

电子邮件只能从服务器发送。正在从服务器和客户端调用Meteor.methods()

尝试以下方法:

Meteor.methods({
  sendEmail: function(options) {
    if(Meteor.isServer){
      this.unblock();
      Email.send(options);
    }
  }
});