`emailrelay-check-ipaddress.pl `_ ---------------------------------------------------------------- .. code:: perl #!/usr/bin/env perl # # SPDX-FileCopyrightText: 2026 Graeme Walker # SPDX-License-Identifier: FSFAP # # Copyright (c) 2026 Graeme Walker # # Copying and distribution of this file, with or without modification, # are permitted in any medium without royalty provided the copyright # notice and this notice are preserved. This file is offered as-is, # without any warranty. # === # # emailrelay-check-ipaddress.pl # # An example E-MailRelay filter script that verifies the # submitting client's IP address. The IP address is read # from the envelope file. Invalid IP addresses are rejected # by deleting the two message files and exiting with the # special exit code of 100. Note that this checks the IP # address very late in the submission process; a firewall # or DNSBL check might work better. # use strict ; use warnings ; use IO::File ; $SIG{__DIE__} = sub { (my $e = join(" ",@_)) =~ s/\n/ /g ; print "<>\n<>\n" ; exit 99 } ; my %allow = ( "127.0.0.1" => 1 , "1.1.1.1" => 1 , # etc ) ; my $content = $ARGV[0] or die "usage error\n" ; my $envelope = $ARGV[1] or die "usage error\n" ; my $fh = new IO::File( $envelope ) or die "cannot open envelope file: $!\n" ; my $txt ; { local $/ = undef ; $txt = <$fh> ; } my ( $ip ) = ( $txt =~ m/X-MailRelay-Client: (\S*)/m ) ; if( $allow{$ip} ) { exit( 0 ) ; } else { print "<>\n<>\n" ; unlink( $content ) ; unlink( $envelope ) ; exit( 100 ) ; } .. _../examples/emailrelay-check-ipaddress.pl: emailrelay-check-ipaddress_pl.html