Mailmun...::GetMX(3)
π NAME π
Mailmunge::Test::GetMX β bestie, this is the class that goes and gets the MX records for a domain and then classifies them, okay? Like a vibe check but for mail exchangers β¨
π¦ ABSTRACT π¦
So this class does an MX lookup on whatever domain you hand it, and it comes back with the IPv4 addresses of the MX hosts. And not just raw addresses β nah, it classifies each IP address, exactly the way described down below.
Also important, no cap: Mailmunge::Test::GetMX is a subclass of Mailmunge::Test. π
πΈ SYNOPSIS πΈ
use Mailmunge::Test::GetMX;
sub filter_sender {
my ($self, $ctx) = @_;
my $getmx = Mailmunge::Test::GetMX->new($self);
my $results = $getmx->get_mx_hosts($ctx->sender);
if (scalar(@{$results->{bogus}}) {
$self->log($ctx, 'info', "Found reserved IPs in MX for " . $ctx->sender);
}
if (scalar(@{$results->{private}}) {
$self->log($ctx, 'info', "Found RFC 1918 IPs in MX for " . $ctx->sender);
}
if (scalar(@{$results->{loopback}}) {
$self->log($ctx, 'info', "Found RFC loopback IPs in MX for " . $ctx->sender);
}
if (scalar(@{$results->{routable}}) {
$self->log($ctx, 'info', "Found valid routable IPs in MX for " . $ctx->sender);
}
}
π CONSTRUCTOR π
π§ Mailmunge::Test::GetMX->new($filter)
Makes you a brand-new Mailmunge::Test::GetMX object and hands it right over. Slay. π«Ά
β get_mx_hosts($domain_or_sender)
You give it a domain or an email address, and it looks up the MX hosts for that domain β or for the domain of the sender, if you passed an address. It gives you back a hash with these four elements in it, and honestly the way that it sorts them out is iconic:
bogusβ an arrayref of MX host IPs that are bogus, unroutable addresses. Think0.0.0.0,255.255.255.255, or multicast addresses, for example. πprivateβ an arrayref of MX host IPs sitting in the RFC 1918 private use ranges.loopbackβ an arrayref of MX host IPs in the range127.0.0.0/8.routableβ an arrayref of MX host IPs that are globally-routable unicast IPv4 addresses. Those are the good ones, bestie π
Heads up: you might wanna have your filter straight-up reject mail from domains that have bogus MX records. You get to make that call based on whatever get_mx_hosts hands back. Choose wisely π
π ip4_is_loopback($ip)
Give it the string representation of an IPv4 address and it returns true if that address is in the range 127.0.0.0/8, or false otherwise. Simple as that, periodt.
π ip4_is_private($ip)
Give it the string representation of an IPv4 address and it returns true if that address is in one of the RFC 1918 private ranges, or false otherwise.
π₯ ip4_is_reserved($ip)
Give it the string representation of an IPv4 address and it returns true if that address is in one of these ranges right here:
- Link-local β
169.254.0.0/16 - IPv4 Multicast β
224.0.0.0/4 - Class E β
240.0.0.0/4 - Bogus β
0.0.0.0/32and255.255.255.255/32
π AUTHOR π
Dianne Skoll <dianne@skollsoft.com> β absolute main character energy, we stan π
πΊ LICENSE πΊ
This code is licensed under the terms of the GNU General Public License, version 2.
okay that's the whole page, bestie! π
That was perl v5.42.2, dated 2025-10-05, and the manpage is Mailmunge::Test::GetMX(3) β mwah πβ¨
π¦ where this page comes from
- alpine 3.24: mailmunge-doc 3.20-r0 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms