【问题标题】:EmailJS and ExpressJS on AppFogAppFog 上的 EmailJS 和 ExpressJS
【发布时间】:2013-02-23 05:52:33
【问题描述】:

我在 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"
    });
}

使用 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);
  }
});

【问题讨论】:

    标签: express appfog


    【解决方案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);
      }
    });
    

    【讨论】:

    • 好的,谢谢,它适用于 sendgrid 模块。我用正确的代码更新了我的主题。
    猜你喜欢
    • 2013-02-08
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 1970-01-01
    • 2021-06-02
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多