2014-03-01 42 views
7

運行,我有以下流星方法設置:流星電子郵件沒有定義,而是從Meteor.methods

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

我稱之爲是這樣的:

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

我得到兩個錯誤,一個在瀏覽器控制檯:

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....) 
在我的服務器殼其他

運行meteor

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

發生了什麼事?我覺得我已經完全按照documentation's instructions,而且我沒有做過類似錯誤的任何事情,例如this onethis one等問題。

+0

當您運行meteor服務器時,您是否爲您的smtp服務設置了MAIL_URL環境變量? – Paul

+0

另外,試着把第一個塊'Meteor.methods'放在/ server **中** – Paul

+0

@Paul,我沒有設置這個變量,我只是意識到我甚至沒有*一個smtp服務。哈我想我假設流星傢伙照顧所有的包裹。讓人驚訝。 – blaineh

回答

5

由於paul建議,它看起來像錯誤是,你正試圖從客戶端撥打Email.send()

Email.send()只能在服務器上調用。要解決該問題,請嘗試將方法定義移動到服務器。

Email.send()

6

你添加的電子郵件包?

meteor add email 
+0

我也需要這樣做!我現在覺得很蠢......我總是點擊文檔中的Email.send鏈接,所以我從來沒有看到上面的標題,關於如何連接它ha – blaineh

+0

我認爲,因爲帳戶包發送電子郵件過去,電子郵件功能也可以開箱即用。我錯了。謝謝你。 – scald