首页 > 解决方案 > Nodemailer 联系表单被提交虚假数据的垃圾邮件机器人击中

问题描述

垃圾邮件机器人从我的快递应用程序向我的 nodemailer 联系表单提交虚假数据时遇到问题,该应用程序位于数字海洋水滴上。

我尝试设置一个隐藏的表单字段来重定向并阻止表单提交,但这似乎不起作用。

app.post("/products/contactCorporate", function (req, res) {
  let { name, email, message, businessAddress } = req.body;

  //businessAddress is a hidden field on my form
  if (businessAddress.length !== 0) {
    req.flash('success', 'Sorry Bot!');
    res.redirect("/products/contactCorporate");
  } else {
    submitForm();
  }
});

我想找到一个 NPM 包或解决方案来在提交表单之前验证后端的电子邮件或以某种方式欺骗机器人。我宁愿不使用验证码。

任何帮助是极大的赞赏。

标签: node.jsexpressnodemailer

解决方案


我能够使用 NPM 包完成它的电子邮件存在

存在是通过远程登录到电子邮件域的 MX 服务器并尝试向提供的地址发送电子邮件来确定的。如果电子邮件地址存在,MX 服务器返回 250,否则返回 550。

app.post("/products/contactCorporate", function (req, res) {
  let { name, email, message, businessAddress } = req.body;

  emailExistence.check(email, function (error, response) {
    if (response === false) {
      req.flash('success', 'Sorry, the email seems to be spam!');
      res.redirect("/products/contactCorporate");
    } else {
      submitForm();
    }
  });
});

推荐阅读