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

I am running HPUX 11i and Perl 5.6.1. Whenever I use the following snippit of code in cron I get the response:
Server error: 553 malformed address: <@somewhere.com>
Here's my code:
ref ($sender = new Mail::Sender()) or die "From $sname: $Mail::Sender::Error\n"; (ref ($sender->MailFile( {to => $addr, subject => 'HP Notify Attachment', msg => "The attachment sent courtesy of $sname.", file => $fname })) ) or die "From $sname: $Mail::Sender::Error\n";
It doesn't seem to matter if I wrap the address in quotes or not. I've even gone to the trouble to hardcode the address on the 'to' line. The code works fine as long as it's not in cron. Does anyone have any ideas? Thanks in advance, killraven

Replies are listed 'Best First'.
Re: Mail::Sender returns malformed address
by talexb (Chancellor) on Mar 25, 2002 at 15:10 UTC
    Recall that running under cron you don't have the same environment that you do under a shell session. You may need to explicitly describe the paths required to run the script, with either use lib statements in the script, or an environment definition on the crontab file.

    --t. alex

    "Here's the chocolates, and here's the flowers. Now how 'bout it, widder hen, will ya marry me?" --Foghorn Leghorn

      I should have been more explicit. The same code works under HPUX11 and Perl 5.6.0. I did have the script run my .profile as well as setting up some default paths as well as trying to get bourne shell out of the equation by doing the following on the crontab line.
      30 09 * * * /usr/bin/ksh $HOME/testmail.sh
      Which in turn calls the perl script that's failing, to no avail. I thought about the use lib but I'm successfully using Mail::Util so I wouldn't think it would help. killraven
Re: Mail::Sender returns malformed address
by particle (Vicar) on Mar 25, 2002 at 15:09 UTC
    what is the address? if it is "@somewhere.com" (as reported in the error message,) it's not valid. check your data.

    ~Particle ;Þ

      The address is in the form:
      myname@somewhere.com.
        The address is in the form:

        myname@somewhere.com.

        Are you sure?

        I'd be interested in seeing the STDERR of this (run as a cron)...

        use Data::Dumper; $sender->MailFile( {to => $addr, subject => 'HP Notify Attachment', msg => "The attachment sent courtesy of $sname.", file => $fname }); warn "Unexpected addr: '$addr'" unless ($addr eq 'myname@somewhere.com'); warn Dump($sender);

        As I recall, the only thing Mail::Sender ever does to a 'to' addr, is replace sequences of whitespaces with a single ", " -- so I would guess either you aren't including myname in your $addr properly, or you have some whitespace seperating if from @somewhere so your SMTP server winds up seeing:

        To: myname, @somewhere.com
        Have you tried to escape the @ ? Like: myname\@somewhere.com I've noticed alot of scripts require the escaping if the address is in double quotes. It's worth a try.