nifu has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
i use a PERL script with Mail::SPF to check the SPF-records from received emails. The PERL module seems to have problems with the DNS. After 1-2 min. i get the error: unresolvable name: nameserver at /usr/share/perl5/Mail/SPF/Server.pm line 225

The network and resolf.conf settings from the debian 8 seams to be ok. I have no problems to resolve the IP from google.com or other names. I tried the solution from https://archive.kiza.eu/journal/entry/720 and added a line with localhost in resolf.con, unfortunately this did not help.

This is my code:
#! /usr/bin/perl use strict; use Socket; use warnings; use Email::Simple; use DBI; use File::Copy; use Date::Parse; use DateTime; use Path::Tiny qw(path); use Mail::DKIM::Verifier; use Mail::SPF; use Encode; use utf8; open (MESSAGE, "< $ARGV[0]") || die "Couldn't open email $ARGV[0]\n"; undef $/; my $raw_email = <>; close MESSAGE; my $mail = Email::Simple->new($raw_email); my $return_path = $mail->header("Return-Path"); my $from_header = $mail->header("From"); my $ip = $mail->header("X-IP"); my $spf = &spf_check($ip,$return_path); sub spf_check { my ($ip, $domain); ($ip, $domain) = @_; $domain =~ s/<|>//g; $domain =~ s/^.*@//g; my $spf_server = Mail::SPF::Server->new(); my $spf_request = Mail::SPF::Request->new ( versions => [1,2], scope => 'mfrom', identity => $domain, ip_address => $ip ); my $return = $spf_server->process($spf_request); }
Is the error in my PERL source code or in the system settings of the linux OS?

kind regards
nifu

Replies are listed 'Best First'.
Re: DNS problems with Mail::SPF
by Corion (Patriarch) on Aug 01, 2018 at 07:03 UTC
    unresolvable name: nameserver

    That sounds to me as somewhere within your system configuration, or maybe in one of the mails you check, there is the word nameserver, occurring as a value of a nameserver to contact.

    Most likely something somewhere is misconfigured, but it's hard to see where, as we don't know your system configurations and the mails you're checking SPF on.

      It is a very strange error. My test mails are OK. I have also tried the script with static IPs and domains. The DNS settings seams to be Okay:
      cat /etc/resolv.conf
      nameserver 80.237.128.144
      nameserver 80.237.128.145
      

      It seems to depend where the line my $spf_server = Mail::SPF::Server->new(); is in the script. It only works when the line is direct after my using directive.
      pass (Mechanism 'ip4:185.82.77.171' matched)

        The filename should be /etc/resolv.conf. If you copy and pasted the command line, maybe you are looking at the wrong file?

Re: DNS problems with Mail::SPF
by rizzo (Curate) on Aug 02, 2018 at 08:55 UTC
    my $ip = $mail->header("X-IP");

    Did you check if $ip has a reasonable value(the sender's IP address)?
    As far as I know, header names starting with "X-" are non-standard, so they may exist but they do not necessarily. I'd bet that an empty string is causing you the trouble.