AppFog上的EmailJS和ExpressJS

时间:2013-02-23 05:52:33

标签: express appfog

我在AppFog上托管了我的Express App,我遇到了EmailJS的问题。 (https://github.com/eleith/emailjs

我收到邮件但是我收到此错误,在本地,我没有看到这个错误:

    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: ‘example@example.com’,
  from: ‘other@example.com’,
  subject: ‘Hello World’,
  text: ‘My first email through SendGrid’
}, function(success, message) {
  if (!success) {
    console.log(message);
  }
});

1 个答案:

答案 0 :(得分:1)

您正在尝试使用Sendgrid的smtp服务器。相反,您应该使用sendgrid模块:

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

SendGrid.send({
  to: 'you@me.com',
  from: 'me@you.com',
  subject: 'subject',
  text: 'some text;'
}, function(success, message) {
  if (!success) {
    console.error('sendgrid.send error:', message);
  }
});