Mailmun...::GetMX(3)

πŸ“¦ version 3.20, in alpine 3.24

πŸ’– 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. Think 0.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 range 127.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/32 and 255.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