0

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 !== "abc@123.com") {
            return callback(
                new Error("Invalid adress!")
            );
        }
        return callback();
    },

    onRcptTo(adress, session, callback) {
        if (adress.adress !== "abc@123.com") {
            return callback(
                new Error("Only abc@123.com 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.

klade
  • 1
  • 1
  • You have 5 variables named callback. Which one is it complaining about? – Quentin Jul 31 '23 at 23:10
  • It's complaining about the one on line 22 onConnect(session, callback) { console.log("A client connected!") return callback(); }, – klade Jul 31 '23 at 23:12

0 Answers0