首页 > 解决方案 > 如何在不发送验证电子邮件的情况下使用 NodeJS 验证电子邮件是否存在

问题描述

如何在不发送电子邮件的情况下验证电子邮件

如果用户使用“asdasdasdada@email.com”之类的电子邮件注册,我需要验证该电子邮件是否存在,并且我可以发送电子邮件。

我已经尝试过使用 deep-email-validator 但它不能正常工作,它说现有的电子邮件无效

async function isEmailValid(email: string) {
  return emailValidator(email);
}

const result = isEmailValid('<my real email>');
console.log(result)

输出:

{
  valid: false,
  validators: {
    regex: { valid: true },
    typo: { valid: true },
    disposable: { valid: true },
    mx: { valid: false, reason: 'MX record not found' },
    smtp: { valid: false }
  },
  reason: 'mx'
}

标签: javascriptnode.jsexpressemailemail-verification

解决方案


deep-email-validator可能会返回不准确的结果,这取决于您的 IP 地址的声誉,甚至可能会损害它 - 请注意。

Verifalia是一个基于云的托管电子邮件验证 SaaS,它允许在不发送任何验证电子邮件的情况下验证电子邮件地址是否存在,并且对您的 IP 地址没有任何风险:它带有一个免费和开源的npm 包(用于Node.js 和浏览器)您可以轻松插入支持 CommonJS 模块系统以及 ES 模块(在 Node.js v13 及更高版本中可用)的 Node.js 应用程序。

以下是安装后如何在 Node.js 中使用 Verifalia 验证电子邮件地址的方法 ( npm install verifalia):

const { VerifaliaRestClient } = require('verifalia');

// ...

const verifalia = new VerifaliaRestClient({
    username: 'username',
    password: 'password'
});

const validation = await verifalia
    .emailValidations
    .submit('batman@gmail.com', true);

// At this point the address has been validated: let's print
// its email validation result to the console.

const entry = validation.entries[0];
console.log(entry.inputData, entry.classification, entry.status);

// Prints out something like:
// batman@gmail.com Deliverable Success

要了解有关 Verifalia 工作原理的更多信息,请参阅:https ://verifalia.com/how-it-works


免责声明:我是 Verifalia 的 CTO。;)


推荐阅读