blaineh
blaineh

Reputation: 2333

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

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.

Upvotes: 7

Views: 2245

Answers (2)

mb.
mb.

Reputation: 1293

Did you add the email package?

meteor add email

Upvotes: 6

1321941
1321941

Reputation: 2180

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()

Upvotes: 5

Related Questions