【问题标题】:simpleSMTP User Auth简单的 SMTP 用户验证
【发布时间】:2013-09-17 22:00:40
【问题描述】:

我正在尝试使用 nodejs 构建一个 SMTP 服务器并卡在用户身份验证上。如何创建一个函数来使用 user: foo 和 pass: bar 对用户进行身份验证?

var simplesmtp = require("simplesmtp"),
    fs = require("fs");

var options = {
    requireAuthentication: true,
    debug: true
};

var smtp = simplesmtp.createServer(options);
smtp.listen(9845);

smtp.on("authorizeUser", function (connection, username, password, callback) {
    callback(new Error("Auth fail!"), true);

});

smtp.on("startData", function(connection){
    console.log("Message from:", connection.from);
    console.log("Message to:", connection.to);
    connection.saveStream = fs.createWriteStream("message.txt");
});

smtp.on("data", function(connection, chunk){
    connection.saveStream.write(chunk);
});

smtp.on("dataReady", function(connection, callback){
    connection.saveStream.end();
    console.log("Incoming message saved to message.txt");
    callback(null, "ABC1"); // ABC1 is the queue id to be advertised to the client
    //callback(new Error("Rejected as spam!")); // reported back to the client
});

【问题讨论】:

    标签: node.js mail-server


    【解决方案1】:

    你尝试过这样的事情吗?

    smtp.on("authorizeUser", function (connection, username, password, callback) {
        if (username == "foo" && password == "bar") {
            callback(null, true);
        } else {
            callback(new Error("Auth fail!"), false);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2016-12-13
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 2013-07-08
      • 2011-05-18
      相关资源
      最近更新 更多