smtp-server icon indicating copy to clipboard operation
smtp-server copied to clipboard

Received mails not detecting for the SMTP server in my application

Open vinodhreddygs opened this issue 5 years ago • 1 comments

Hi, Using the smtp-server listener Iam trying to receive mails. (But Authentication is not happening. Even emails are not detecting). Please check the below code snippet that iam using and let me know if I have done any wrong. (No consoles are printing expect console.log("starts listening on 465>>>") in the below code snippet).

var SMTPServer = require('smtp-server').SMTPServer;


var server = new SMTPServer({
    tls:true,
    logger: true,
    onAuth(auth, session, callback) {
        console.log("Console in auth function>>>",auth);
        if (auth.username != config.mail_username || auth.password != config.mail_password) {
          return callback(new Error("Invalid username or password"));
        }
        console.log("Authentication successfull>>>")
        return callback();
    },
    onConnect(session, callback) {
        console.log("Console in onConnect function>>>",session);
        if (session.remoteAddress === "127.0.0.1") {
          return callback(new Error("No connections from localhost allowed"));
        }
        return callback(); // Accept the connection
    },
    onMailFrom(address, session, callback) {
        console.log("Received mail from function>>>",address);
        if (address.address !== "[email protected]") {
          return callback(
            new Error("Only [email protected] is allowed to send mail")
          );
        }
        return callback(); // Accept the address
    },
    onData(stream, session, callback) {
        console.log("Console at onData function>>>",onData);
        stream.pipe(process.stdout); // print message to console
        stream.on("end", callback);
      }
});
// mailListener.listen(465) // start listening
server.listen(465, function () {
console.log("starts listning on 465>>>")
})
server.on("error", err => {
    console.log("Error %s", err.message);
  });

server.on('error', err => {
    console.log("Error on server start",err.message);
  });

server.listen(465);

vinodhreddygs avatar Apr 23 '20 07:04 vinodhreddygs

Same error

andrealeo83 avatar May 27 '21 14:05 andrealeo83