Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: write ECONNRESET when listening to validateSender #113

Open
dudilugasi opened this issue Dec 1, 2016 · 3 comments
Open

Error: write ECONNRESET when listening to validateSender #113

dudilugasi opened this issue Dec 1, 2016 · 3 comments

Comments

@dudilugasi
Copy link

mailin.on('validateSender',function (connection, email, next) {
next(null);
});
mailin.on('message', mailModule.emailRecieved);

this causes :
error: Error: write ECONNRESET
at exports._errnoException (util.js:1022:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:804:14)
Error: Uncaught, unspecified "error" event. ([object Object])
at Mailin.emit (events.js:163:17)
at SMTPServer. (/home/bitnami/attacksServer/node_modules/mailin/lib/mailin.js:519:15)
at emitOne (events.js:96:13)
at SMTPServer.emit (events.js:188:7)
at SMTPServer._onError (/home/bitnami/attacksServer/node_modules/smtp-server/lib/smtp-server.js:237:10)
at emitOne (events.js:96:13)
at SMTPConnection.emit (events.js:188:7)
at SMTPConnection._onError (/home/bitnami/attacksServer/node_modules/smtp-server/lib/smtp-connection.js:274:10)
at emitOne (events.js:101:20)
at TLSSocket.emit (events.js:188:7)
at onwriteError (_stream_writable.js:346:10)
at onwrite (_stream_writable.js:364:5)
at WritableState.onwrite (_stream_writable.js:90:5)
at fireErrorCallbacks (net.js:471:13)
at TLSSocket.Socket._destroy (net.js:512:3)
at WriteWrap.afterWrite [as oncomplete] (net.js:806:10)

@senica
Copy link

senica commented May 24, 2017

I get the following error when using validateSender

Error: Data command failed: 500 Error: command not recognized
      at SMTPConnection._formatError (node_modules/nodemailer/lib/smtp-connection/index.js:555:19)
      at SMTPConnection._actionDATA (node_modules/nodemailer/lib/smtp-connection/index.js:1352:34)
      at SMTPConnection._responseActions.push.str (node_modules/nodemailer/lib/smtp-connection/index.js:1324:26)
      at SMTPConnection._processResponse (node_modules/nodemailer/lib/smtp-connection/index.js:702:20)
      at SMTPConnection._onData (node_modules/nodemailer/lib/smtp-connection/index.js:507:14)
      at readableAddChunk (_stream_readable.js:176:18)
      at TLSWrap.onread (net.js:554:20)

@RomanKer
Copy link

I also can confirm this behavior by using validateSender with mailin 3.0.4 on node v6.11.0

If the validation is activated the SMTPConnection.prototype._onCommand ( .\node_modules\smtp-server\lib\smtp-connection.js ) function is called with an empty command.
This causes the "500 Error: command not recognized" and the remote server closes the connection.

The order of the commands the function is called is the following:

EHLO
MAIL
empty
RCPT
DATA

Seems that SMTPConnection.prototype._onCommand is called twice and the second time without a command what causes the error.

Here the communication log between the Client and the Server:

[2017-08-17 10:07:22] DEBUG Creating transport: nodemailer (4.0.1; +https://nodemailer.com/; SMTP/4.0.1[client:4.0.1])
SMTP Configured
Sending Mail
[2017-08-17 10:07:22] DEBUG Sending mail using SMTP/4.0.1[client:4.0.1]
[2017-08-17 10:07:22] INFO  [XyVQYHp1l3s] Connection established to 127.0.0.1:9090
[2017-08-17 10:07:22] DEBUG [XyVQYHp1l3s] S: 220 WS01 ESMTP Mailin Smtp Server
[2017-08-17 10:07:22] DEBUG [XyVQYHp1l3s] C: EHLO [127.0.0.1]

SMTPConnection.prototype._onCommand is called with "EHLO"

[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] S: 250-WS01 Nice to meet you, localhost
[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] S: 250-PIPELINING
[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] S: 250-8BITMIME
[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] S: 250-SMTPUTF8
[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] S: 250 STARTTLS
[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] SMTP handshake finished
[2017-08-17 10:07:28] INFO  Sending message <3e497a2e-c208-f30e-5339-1ab9a4b083eb@xxx.org> to <xxx@xxx.com>
[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] C: MAIL FROM:<xxxx@xxx.org>

SMTPConnection.prototype._onCommand is called with "MAIL" and will be accepted

[2017-08-17 10:07:34] DEBUG [XyVQYHp1l3s] S: 250 Accepted

After that and before the SMTPConnection.prototype._onCommand is called with "RCPT" the SMTPConnection.prototype._onCommand is called with an empty command.

[2017-08-17 10:07:34] DEBUG [XyVQYHp1l3s] C: RCPT TO:<xxx@xxx.com>
[2017-08-17 10:07:34] DEBUG [XyVQYHp1l3s] S: 250 Accepted
[2017-08-17 10:07:34] DEBUG [XyVQYHp1l3s] C: DATA
[2017-08-17 10:08:21] DEBUG [XyVQYHp1l3s] S: 500 Error: command not recognized
[2017-08-17 10:08:21] DEBUG [XyVQYHp1l3s] Closing connection to the server using "end"
[2017-08-17 10:08:21] ERROR Send error for <3e497a2e-c208-f30e-5339-1ab9a4b083eb@xxx.org>: Data command failed: 500 Error: command not recognized
[2017-08-17 10:08:21] ERROR Send Error: Data command failed: 500 Error: command not recognized
Error occurred
Data command failed: 500 Error: command not recognized
[2017-08-17 10:08:43] INFO  [XyVQYHp1l3s] Connection closed

@RomanKer
Copy link

RomanKer commented Sep 2, 2017

The issue is that the validateSender event is called twice, if the "local check" is configured. This causes an error in the smtp communication (as described above).

As the event is handeled by the validateAddress function, there is no need for summiting the event twice for DNS and local check. If DNS is set up (disableDNSValidation: false – default), both will be checked and if one returns an error, this error will be passed to the sender.

So my solution is to remove / comment out the line 460 in lib/mailin.js - https://github.com/RomanKer/mailin/commit/a75ba2b3522ec3e6a169328a77ea1d69eada0aa6

As I didn’t find any other case, where this event should be called twice, this seems to be the working solution for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants