Reputation: 3
I'm trying to make an SMTP server and client using Nodemail & ExpressJS. For now, I'm just attempting to "login" to my SMTP server to test & verify its working. When I go to localhost/listen
, I get:
ReferenceError: callback is not defined
Below is my full code;
var express = require('express');
var app = express();
const STMP__Connection = require("nodemailer/lib/smtp-connection");
let connection = new STMP__Connection({
port: 465,
secure: false
})
const SMTP_server = require("smtp-server").SMTPServer;
const SMTPserver = new SMTP_server({
onAuth(auth, session, callback) {
if (auth.username !=="abc" || auth.password !=="123") {
console.log("zort");
return callback(new Error("Incorrect username/password"));
}
console.log("SUCCESS!");
callback(null, {user : 999});
},
onConnect(session, callback) {
console.log("A client connected!")
return callback();
},
onMailFrom(adress, session, callback) {
if (adress.adress !== "[email protected]") {
return callback(
new Error("Invalid adress!")
);
}
return callback();
},
onRcptTo(adress, session, callback) {
if (adress.adress !== "[email protected]") {
return callback(
new Error("Only [email protected] can recieve mail.")
);
}
return callback();
},
onData(stream, session, callback) {
stream.pipe(process.stdout);
stream.on("end", callback);
}
});
SMTPserver.listen(465);
SMTPserver.on("error", err => {
console.log("Error %s", err.message)
})
app.get("/listen", function(req,res) {
connection.connect();
connection.login({
user: "abc",
pass: "123"
})
});
app.listen(80);
I tried running it with just
connection.connect();
but that resulted in a TypeError: this._socket.write is not a function
error.
Running with connection.connect("callback");
also resulted in the same error message.
Upvotes: 0
Views: 36