Skip to main content

Check if the sender domain exists

It's somewhat common check if a sender domain exists before accepting mail. This check is technically backed by the standard however in practice it is prune to false-positives, so we can't fully endorse this method of anti-spam prevention. The standard argues that since mail should be transactionally safe, the return/sender address has to be valid so that non-delivered mail can be returned to the sender.

MAIL FROM context
if ($arguments["address"]["domain"]) {
$dnsa = dns_query($arguments["address"]["domain"], ["type" => "a"]);
$dnsaaaa = dns_query($arguments["address"]["domain"], ["type" => "aaaa"]);
$dnsmx = dns_query($arguments["address"]["domain"], ["type" => "mx"]);
if ($dnsa["error"] == "NXDOMAIN" and $dnsaaaa["error"] == "NXDOMAIN" and $dnsmx["error"] == "NXDOMAIN") {
Reject($arguments["address"]["domain"]." doesn't exist");
}
}

This check, can be done in the MAIL FROM context or at any later stage.