1

我在 AppFog 上托管了我的 Express 应用程序,但我遇到了 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"
    });
}

使用发送网格:

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);
  }
});
4

1 回答 1

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);
  }
});
于 2013-02-23T06:38:02.570 回答