繁体   English   中英

nodemailer smtp-server 给出 421 mydomain.com 你说得太早了错误

[英]nodemailer smtp-server giving 421 mydomain.com You talk too soon error

我正在使用http://nodemailer.com/extras/smtp-server/运行 SMTP 服务器来接受所有邮件提交。
当邮件提交代理使用 STARTTLS 时,我收到以下错误。

5|producer  | [2020-10-09 07:28:52] DEBUG [#ff7cqlwi7rat6z2k] C: EHLO qa.mydomain.com
5|producer  | [2020-10-09 07:28:52] DEBUG [#ff7cqlwi7rat6z2k] S: 421 mydomain.com You talk too soon
5|producer  | [2020-10-09 07:28:52] INFO  [#ff7cqlwi7rat6z2k] Connection closed to 91.198.201.301

但是,这种情况只发生在某些客户端上,我尝试过使用其他一些工具,它可以将连接升级到 TLS,没有任何问题。

以下是我的服务器配置选项。

SMTPServerOptions = { 
  secure: false,
  hideSTARTTLS:true,
  authOptional: true,
  debug: true,
  logger: true,
  onAuth,
  onData
}

if(conf.tls) {
  SMTPServerOptions.ca = fs.readFileSync('./certificates/chain.pem', 'ascii')
  SMTPServerOptions.key = fs.readFileSync('./certificates/privkey.pem','ascii')
  SMTPServerOptions.cert = fs.readFileSync('./certificates/cert.pem','ascii')
}
//creating new SMTP object
const server = new SMTPServer(SMTPServerOptions);

server.on('error', err => {
  error(err)
  throw err 
});

server.listen(conf.server_port);


能够通过在 nodemailer smtp-server 模块中注释代码的某些部分来解决这个问题。 只是在这里发布,以便它可以帮助其他正在寻求相同答案的人。

一些 SMTP 客户端,比如我使用的那个,在连接后不等待服务器响应,而是向服务器发送 EHLO 或 HELO 命令。 从模块的源代码来看,这些客户端被视为早期谈话者,并且连接被阻止以避免垃圾邮件。
评论超时函数并发出 connectionReady() 事件立即解决了问题。

     /**
     * Initiates the connection. Checks connection limits and reverse resolves client hostname. The client
     * is not allowed to send anything before init has finished otherwise 'You talk too soon' error is returned
     */
    init() {
        // Setup event handlers for the socket
        this._setListeners(() => {
            // Check that connection limit is not exceeded
            if (this._server.options.maxClients && this._server.connections.size > this._server.options.maxClients) {
                return this.send(421, this.name + ' Too many connected clients, try again in a moment');
            }
            // Keep a small delay for detecting early talkers
            //setTimeout(() => this.connectionReady(), 100);

            // no need to detect the early talkers
            this.connectionReady();
        });
    }

如果需要时间,还要禁用反向查找。

 // disabling the reverse lookup which will solve 'you talk so soon problem'
 this.options.disableReverseLookup = true;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM