javascript - 如何在不发送验证电子邮件的情况下使用 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'
}
解决方案
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。;)
推荐阅读
- c# - 如何防止大量请求客户端到 Web API(c#)?
- teradata - 如何解决加载数据时出现以下错误
- android - 损坏的 AVD 系统路径。检查您的 ANDROID_SDK_ROOT 值 [c:\android-sdk]
- clojure - 如何从解放者的请求中提取表单数据?
- angular - Angular ngbDatePicker - ng 触摸验证不起作用
- vba - 在文档中定义/查找 Word 宏变量
- python - 有没有办法将对象数据框转换为在 python 2 上浮动
- powershell - 如何知道在创建 Chocolatey 包时使用什么silentArg?
- c# - C# 使用 Telnet 连接导航 OpenVMS 菜单
- bash - 压缩文件夹及其子文件夹