我正在尝试使用 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
});