使用可传递性在 C 中验证电子邮件

Validating Emails in C using deliverability

我正在编写一个 C 项目,需要在存储电子邮件之前对其进行验证。我将不得不交叉编译,所以使用 regex.h 不是一个选项。

是否有一种万无一失的方法来验证电子邮件,通过检查它是否是可送达地址而无需实际在 C 中发送电子邮件?

如果没有办法做到这一点,欢迎提出替代方案或建议。

任何语言都没有这样的程序。

您可以执行 DNS query of the domain name (the part of the e-mail-address after the @ symbol) to determine whether the domain is valid and has an MX record. To verify the username (the part of the e-mail-address before the @ symbol), you will have to query the destination mail server itself, for example using the VRFY SMTP 命令。但是,出于安全原因,某些邮件服务器可能不支持此命令。

C语言本身不提供任何发送网络数据包的函数。但是,大多数平台都提供了一个 API 来提供此功能(例如 POSIX sockets, Windows sockets)。某些平台还提供 API 来为您执行 DNS 查询。此外,还有几个提供此功能的库。