Nodemailer SMTP 服务器接收电子邮件但不响应任何内容

Nodemailer SMTP Server receives e-mail but doesn't respond anything

我有一个简单的接收电子邮件的脚本,即使它接收电子邮件并打印正常,不幸的是,没有响应发送服务器,(没有 250OK)结果发送服务器不断发送相同的电子邮件(重试)

需要回复什么或可能有什么问题?

在此设置中,此代码 运行 在我的本地网络 (OsX) 中,我的路由器端口 25 转发到我的机器。

const SMTPServer = require("smtp-server").SMTPServer;
const parser = require("mailparser").simpleParser

const server = new SMTPServer({

  onData(stream, session, callback) {
    parser(stream, {}, (err, parsed) => {

      if (err){
        console.log("Error:" , err)
      }
      
      eMailParse(parsed)
      stream.on("end", callback)

    })
    
  },
  disabledCommands: ['AUTH']

});

server.listen(25, "192.168.50.20")

console.log("Mail Server Running");


function eMailParse(parsed){
    const {headers, from, to, cc, date, html, text, messageId} = parsed;

    console.log("\n//############# New Mail #############\n")
    console.log(messageId)//Unique Mail ID;
    console.log("\n//$$$$$")
    console.log(from)
    console.log(to)
    console.log(cc)
    console.log(date)
    console.log(text)
    console.log("//====")
    console.log(html)
}

Gmail 的回复

The recipient server did not accept our requests to connect. Learn more at https://support.google.com/mail/answer/7720 [dc-133a13304d09.*******.fun. nn.nnn.nn.nn: timed out]

Telnet 响应

421 Timeout - closing connection Connection closed by foreign host.

过了一段时间,我又尝试了一段时间,找到了解决办法。

这部分不工作

eMailParse(parsed)
stream.on("end", callback) //on("end") is never triggered

相反;

eMailParse(parsed)
callback()

很有魅力。

我最近遇到了同样的问题。我发现这个线程和答案对我也有用,但后来我发现了真正的问题 - 'end' 事件的侦听器应该立即附加在 onData 回调中,而不是在解析器回调中。解决方法如下:

const SMTPServer = require("smtp-server").SMTPServer;
const parser = require("mailparser").simpleParser

const server = new SMTPServer({

  onData(stream, session, callback) {
    stream.on("end", callback)
    parser(stream, {}, (err, parsed) => {
      if (err){
        console.log("Error:" , err)
      }
      
      eMailParse(parsed)
    })
  },
  disabledCommands: ['AUTH']
});

server.listen(25, "192.168.50.20")

console.log("Mail Server Running");


function eMailParse(parsed){
    const {headers, from, to, cc, date, html, text, messageId} = parsed;

    console.log("\n//############# New Mail #############\n")
    console.log(messageId)//Unique Mail ID;
    console.log("\n//$$$$$")
    console.log(from)
    console.log(to)
    console.log(cc)
    console.log(date)
    console.log(text)
    console.log("//====")
    console.log(html)
}