2014-01-18 31 views
3

我需要使用Meteor發送電子郵件。我做了關於發送郵件的代碼。我已經添加了一個包郵件。但是我得到了一個錯誤。我不知道發生了什麼事。檢查下面的錯誤&代碼。Email.send問題是電子郵件未在流星中定義

錯誤:

=> Meteor server running on: http://localhost:3000/ 
I20140118-10:54:35.900(5.5)? Exception while invoking method 'sendEmail' Referen 
ceError: email is not defined 
I20140118-10:54:35.989(5.5)?  at Meteor.methods.sendEmail (app/loginapp.js:13 
7:39) 
I20140118-10:54:35.989(5.5)?  at maybeAuditArgumentChecks (packages/livedata/ 
livedata_server.js:1349) 
I20140118-10:54:35.990(5.5)?  at packages/livedata/livedata_server.js:569 
I20140118-10:54:35.990(5.5)?  at _.extend.withValue (packages/meteor/dynamics 
_nodejs.js:35) 
I20140118-10:54:35.990(5.5)?  at packages/livedata/livedata_server.js:568 
I20140118-10:54:35.992(5.5)?  at _.extend.withValue (packages/meteor/dynamics 
_nodejs.js:35) 
I20140118-10:54:35.992(5.5)?  at _.extend.protocol_handlers.method (packages/ 
livedata/livedata_server.js:567) 
I20140118-10:54:35.992(5.5)?  at packages/livedata/livedata_server.js:472 

JS代碼:

if (Meteor.isClient) 
{ 
    Template.hello.greeting = function() 
    { 
    return "Welcome to email."; 
    }; 

    Template.hello.events 
    ({ 
    'click input' : function() 
    { 
     // template data, if any, is available in 'this' 
     if (typeof console !== 'undefined') 
     console.log("You pressed the button"); 
     // In your client code: asynchronously send an email 
      Meteor.call('sendEmail', 
      '*****@gmail.com', 
      '****@gmail.com', 
      'Hello from Meteor!', 
      'This is a test of Email.send.'); 
    } 
    }); 
} 

if (Meteor.isServer) 
{ 
    Meteor.startup(function() 
    { 
    // code to run on server at startup 
    process.env.MAIL_URL = 'smtp://****@gmail.com:**password**@smtp.sendgrid.net:587'; 

    }); 
    Meteor.methods 
    ({ 
    sendEmail: function (to, from, subject, text) 
    { 
    console.log("*** sendEmail ***"); 

    // Let other method calls from the same client start running, 
    // without waiting for the email sending to complete. 
    this.unblock(); 

    Email.send 
    ({ 
     to: to, 
     from: from, 
     subject: subject, 
     text: text 
    }); 
    } 
}); 
} 
+0

當然這是它在抱怨的代碼?根據例外情況,你引用未定義的變量'error',但在你向我們展示的代碼中,你永遠不會這樣做。 –

+0

@Venkat,在github上發佈完整的重新發布,我們可以進一步提供幫助。 – alanning

回答

3

我認爲你需要有email package installed

meteor add email 
+0

是的,我已經安裝了電子郵件軟件包@pahan – Venkat

+1

@Venkat看着你得到的錯誤,你用了一個小寫的'email',你上面給出的代碼使用了大寫的Email',這是正確的。如果您調整代碼以與您使用的代碼相匹配,則不會有問題。 – Akshat