Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor Email not defined, but is running from Meteor.methods

Tags:

meteor

I have the following Meteor method set up:

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

which I call like this:

// Defined in client/main.js
Meteor.call('email', {
    to: '[email protected]', from: '[email protected]',
    text: 'testing testing'
});

I get two errors, one in the browser console:

Exception while simulating the effect of invoking 'email' 
ReferenceError {stack: "ReferenceError: Email is not defined↵    at Meteor…js?acc2397bd1f7321a583a30e0d4628ec4f9fded4b:369:3", message: "Email is not defined"}
 ReferenceError: Email is not defined
(etc....)

the other in my server shell running meteor:

Exception while invoking method 'email' ReferenceError: Email is not defined
(etc....)

What's going on? I feel like I've followed the documentation's instructions exactly, and I'm not doing anything similarly wrong as in questions like this one or this one.

like image 531
blaineh Avatar asked Mar 01 '14 01:03

blaineh


People also ask

What is Meteor methods?

Methods are Meteor's remote procedure call (RPC) system, used to save user input events and data that come from the client.

What is Meteor call?

Meteor. call() is typically used to call server-side methods from the client-side. However, you can also use Meteor. call() on the server-side to call another server-side function, though this is not recommended.


2 Answers

Did you add the email package?

meteor add email
like image 88
mb. Avatar answered Oct 13 '22 21:10

mb.


As paul suggested, it looks like the error is that you are trying to call Email.send() from the client.

Email.send() can only be called on the server. To solve the issue try moving the method definition to the server.

Email.send()

like image 26
1321941 Avatar answered Oct 13 '22 19:10

1321941