nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
862 stars 146 forks source link

Stream.on("end") is not called #171

Open TheArKaID opened 3 years ago

TheArKaID commented 3 years ago

First, stream.on("end") will called after Data Ended. But how to get into this event ? I mean, I could end it if I use Telnet, just type "." (dot) and stream.on("end") will fired. But I tried with SMTP (nodemailer.createTransport), the "end" event is not called, I could even console.log(parsed) mail with MailParser, and it's stuck until Timed Out, which will give the Transport Timeout Response.

This is my onData callback,

        async onData(stream, session, callback) {
            stream.pipe(process.stdout);
            console.log('test123')
            let data = await mailparser(stream);
            // console.log(data)
            console.log('end123')
            stream.on('end', async () => {
                console.log('end')
                let err;
                if (stream.sizeExceeded) {
                    err = new Error('Error: message exceeds fixed maximum message size 10 MB');
                    err.responseCode = 552;
                    return callback(err);
                }

                callback(null, 'Message queued as abcdef'); // accept the message once the stream is ended
            });
        }

And the log looks like this,

[2021-11-29 06:49:25] DEBUG [#2olhr63d4yyjaq4o] C: DATA
test123
[2021-11-29 06:49:25] DEBUG [#2olhr63d4yyjaq4o] S: 354 End data with <CR><LF>.<CR><LF>
Message-ID: <250aa4cge1bes2e05ed23dcb23535e11a3@swift.generated>
Date: Mon, 29 Nov 2021 13:49:24 +0700
Subject: Test Email . \n\n .
From: MyHealthcare <no-reply@my-com.com>
To: myemail@gmail.com
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hello World!
end123
[2021-11-29 06:50:25] INFO  [#2olhr63d4yyjaq4o] Connection closed to [192.168.10.10]

Another information,

        logger: true
        secure: false,
        banner: 'Welcome to My Mail Service - SMTP Server'
        disabledCommands: ['STARTTLS']
        authMethods: ['PLAIN', 'LOGIN']
        size: 10 * 1024 * 1024
        useXClient: true
        hidePIPELINING: true
        useXForward: true
        SMTPServer.listen(587, 192.168.10.1)

Calling "stream.end()" doesn't call event "end" either. Or, should I just call callback(null, 'success')?

krm35 commented 1 year ago

The stream end event is triggerred in the mailparser method.

https://github.com/nodemailer/smtp-server/issues/187