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

I have a script that sends a spreadsheet to a list of recipients. If I run it from the command line it works just fine. If I run it as a cronjob I get

"FROM: userx@linux.server.com does not end with localhost.localdomain".

I've turned on debugging and I get:

>> 220 int2.disney.pvt ESMTP Sendmail Sentrion-MTA-4.2.2/Sentrion-MTA- +4.2.2; Fri, 21 Jun 2013 12:17:14 GMT << EHLO localhost.localdomain >> 250-int2.disney.pvt Hello linu.server.com [172.27.75.45], pleased t +o meet you >> 250-ENHANCEDSTATUSCODES >> 250-PIPELINING >> 250-8BITMIME >> 250-SIZE 26214400 >> 250-DSN >> 250-ETRN >> 250-STARTTLS >> 250-DELIVERBY >> 250 HELP << MAIL FROM:<userx@xyz..com> >> 550 5.7.1 <userx@xyz.com>... Relaying denied. MAIL FROM: userx.@xy +z.disney.com does not end with localhost.localdomain << quit

The script

#!/usr/bin/perl -w use strict; use Mail::Sender; # need to set PATH for cron? $ENV{'PATH'} = '/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/sb +in:/sbin'; # Get latest KPI spreadsheet my $send_file = 'file_to_send.xls' open my $DEBUG, ">> /tmp/j1.txt" or die "Fail $!\n"; # Set up mail sender my $sender = new Mail::Sender ( { smtp => 'a.relay.server.com', from => 'userx@.xyz.com', debug => $DEBUG, debug_level => 4, }); if ($Mail::Sender::Error) { print "New failed: $Mail::Sender::Error\n"; exit (); } # variables for email # Glenn.Lochen@xerox.com #my $To = q(jesse.carroll@xerox.com, Craig.Elliott@xerox.com); my $To = q(userz.@xyz.com); my $subject = q(A Spreadsheet); my $msg = q(Today's spreadsheet is attached); # send the file $sender->MailFile( { to => $To, subject => $subject, msg => $msg, file => $current_spreadsheet, }); if ($Mail::Sender::Error) { print "Send failed: $Mail::Sender::Error\n"; exit (); } else { print "$current_spreadsheet sent to $To\n"; }

Of course I've change some names. Any help would be greatly appreciated

Replies are listed 'Best First'.
Re: Mail::Sender MAIL FROM: does not end with localhost.localdomain
by walkingthecow (Friar) on Jun 21, 2013 at 14:19 UTC
    Are you able to check the logs for the mail server? It sounds to me like the mail server is not set up as an open relay, thus when the cronjob tries to send the email, the server is saying no, because the server's hostname is localhost.localdomain, and the @domain.com does not match that. I.e., you're not spoofing an email on this server...

    Odd that it would work when not run as a cronjob... Who does the email come from in the actual header when not run as a cronjob? Does it match the address that you're using as the from address in the script?

    Also, you may want to edit out those @xerox.com email addresses. I doubt those people want their email addresses put on here.

      The debug output file eventually pointed me where I should have gone. It turns out that the Mail::Sender module calls 'gethostbyname' which apparently yields the server name when run from the command line but returns "localhost.localdomain" when using cron. Not sure why though. The fix is to add a 'client' line in the new method.

      my $sender = new Mail::Sender ( { smtp => 'a.relay.server.com', from => 'userx@.xyz.com', client => 'linux.server.com', debug => $DEBUG, debug_level => 4, });

      All works now.

      Paradise: Florida, full tank of gas, no appointments.