mailin
mailin copied to clipboard
Error: write ECONNRESET when listening to validateSender
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.
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)
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 <[email protected]> to <[email protected]>
[2017-08-17 10:07:28] DEBUG [XyVQYHp1l3s] C: MAIL FROM:<[email protected]>
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:<[email protected]>
[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 <[email protected]>: 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
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.