nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
863 stars 147 forks source link

Received mails not detecting for the SMTP server in my application #143

Open vinodhreddygs opened 4 years ago

vinodhreddygs commented 4 years ago

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 !== "vinodhreddy33@gmail.com") {
          return callback(
            new Error("Only vinodhreddy33@gmail.com 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);
andrealeo83 commented 3 years ago

Same error