2013-02-23 1 views
1

AppFog에서 Express App을 호스팅했으며 EmailJS에 문제가 있습니다. (https://github.com/eleith/emailjs)AppFog의 EmailJS 및 ExpressJS

내가 메일을받을 그러나 나는이 오류가 지역에서, 나는이 오류가 표시되지 않습니다 얻을 :

Error: addListener only takes instances of Function 
      at SMTPClient.EventEmitter.addListener (events.js:140:11) 
      at SMTPClientPool.send (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/mailer/lib/node_mailer.js:72:10) 
      at dispatchMail (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/mailer/lib/node_mailer.js:112:12) 
      at Object.node_mail [as send] (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/mailer/lib/node_mailer.js:159:5) 
      at send (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/routes/contact.js:8:11) 
      at exports.send (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/routes/contact.js:30:5) 
      at callbacks (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:161:37) 
      at param (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:135:11) 
      at pass (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:142:5) 
      at Router._dispatch (/mnt/var/vcap.local/dea/apps/anthonycluse-0-2effab27785dd5296efe3df6844c0c3a/app/node_modules/express/lib/router/index.js:170:5) 

내 코드를 (로컬에서 작동) :

var Email = require("mailer"); 

var username = '******'; 
var password = '******'; 

var send = function(message, from, subject) { 
    Email.send({ 
     host : "smtp.sendgrid.net", 
     port : "****", 
     domain : "gmail.com", 
     to : "*****@gmail.com", 
     from : from, 
     subject : subject, 
     body: message, 
     authentication : "login", 
     username : username, 
     password : password 
    }); 
} 

exports.index = function(req, res) { 
    res.render('contact', { 
     emailSuccess: false, 
     title: "Contact | Anthony Cluse" 
    }); 
} 

exports.send = function(req, res) { 
    send(req.body.message, req.body.from, req.body.subject); 
    res.render('contact', { 
     emailSuccess: true, 
     title: "title" 
    }); 
} 

SendGrid 사용 :

var SendGrid = require(‘sendgrid’).SendGrid; 

var sendgrid = new SendGrid(user, key); 

sendgrid.send({ 
    to: ‘[email protected]’, 
    from: ‘[email protected]’, 
    subject: ‘Hello World’, 
    text: ‘My first email through SendGrid’ 
}, function(success, message) { 
    if (!success) { 
    console.log(message); 
    } 
}); 

답변

1

Sendgrid의 smtp 서버를 사용하려고합니다. 대신 sendgrid 모듈을 사용해야합니다.

var SendGrid = require('sendgrid').SendGrid; 

SendGrid.send({ 
    to: '[email protected]', 
    from: '[email protected]', 
    subject: 'subject', 
    text: 'some text;' 
}, function(success, message) { 
    if (!success) { 
    console.error('sendgrid.send error:', message); 
    } 
}); 
+0

감사합니다. sendgrid 모듈과 함께 작동합니다. 내 주제를 올바른 코드로 업데이트했습니다. – tonymx227