nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
846 stars 145 forks source link

Stream end event never triggered leads to duplicates #187

Closed krm35 closed 1 year ago

krm35 commented 1 year ago

EDIT: the simpleParser triggers it that's why it's never triggered again.

Hello,

It seems that the stream doesn't trigger the end event , so the 250 OK isn't sent and services like protonmail try to resend the mail multiple times.

I call the callback after the parsing and it works but it shouldn't be done that way.

const {SMTPServer} = require("smtp-server");
const {simpleParser} = require("mailparser");

const server = new SMTPServer({
    onData(stream, session, callback) {
        simpleParser(stream, {}, (err, parsed) => {
            if (err) return callback(err);
            console(parsed);
            /*
            triggered in the simpleParser
            stream.on('end', () => {
                callback(null, 'OK')
            });
            */
            callback(null, 'OK')
        })
    },
    disabledCommands: ['AUTH']
});

server.on("error", () => {
});

server.listen(2525, "127.0.0.1");