H
Henry Law
I have a piece of code that is to send mail using Mail::Internet from my
Linux server (Perl 5.8.0). It reads variables - the recipient, the
outbound mail server and so on - from an XML file into a hash.
Using the variables in the hash causes errors in Mail::Internet; using
equivalent variables from a hash created from data in the program does
not cause the same error. Odder still, the error doesn't occur at all
when I run the same program under ActiveState Perl in Windows.
Can someone help? Firstly I'm at a loss to understand why this might
be; secondly I've run out of ideas for debugging the thing.
The program below simulates the reading of the XML through the use of
__DATA__; it builds the Mail::Internet structures $header and $mail; it
then executes the smtp send using first a structure built in the program
itself ($G_server) and then the XML-derived structure ($g_server). The
program even checks that the corresponding elements in $g_server and
$G_server are the same ...
----------- sample program ------------
#! /usr/bin/perl
use strict;
use warnings;
use Mail::Internet;
use Mail::Header;
use XML::Simple;
my @data = <DATA>;
my $xml = XMLin(join (' ',@data));
my %g_server;
$g_server{adminuser} = $xml -> {adminuser};
$g_server{smtpserver} = $xml -> {smtpserver};
$g_server{localuser} = $xml -> {localuser};
my %G_server = (localuser=>'(e-mail address removed)',
adminuser=>'(e-mail address removed)',
smtpserver=>'smtp.bt.net');
my @message = ("Line 1\n","Line 2");
print ( $g_server{localuser} eq $G_server{localuser} ?
"localuser same\n" : "localuser different\n");
print ( $g_server{adminuser} eq $G_server{adminuser} ?
"adminuser same\n" : "adminuser different\n");
print ( $g_server{smtpserver} eq $G_server{smtpserver} ?
"smtpserver same\n" : "smtpserver different\n");
my $header = Mail::Header->new( ["From:$g_server{localuser}",
"Sender:$g_server{localuser}",
"To:$g_server{adminuser}",
"Subject:Testing"] );
my $mail = Mail::Internet->new(Header=>$header,Body=>\@message);
my @recipients;
print "Sending with G_server variables\n";
@recipients = $mail->smtpsend(Host=>$G_server{smtpserver},
MailFrom=>$G_server{localuser},
To=>$G_server{adminuser});
print "Mail sent to @recipients\n";
print "Sending with g_server variables\n";
@recipients = $mail->smtpsend(Host=>$g_server{smtpserver},
MailFrom=>$g_server{localuser},
To=>$g_server{adminuser});
print "Mail sent to @recipients\n";
__DATA__
<nfbserver>
<adminuser>[email protected]</adminuser>
<smtpserver>smtp.bt.net</smtpserver>
<localuser>[email protected]</localuser>
</nfbserver>
----------------- output under Linux ----------------
[nfb@neptune nfb]$ ./tryit.pl
localuser same
adminuser same
smtpserver same
Sending with G_server variables
Mail sent to (e-mail address removed)
Sending with g_server variables
Unrecognised line: (e-mail address removed) at blib/lib/Mail/Internet.pm
(autosplit into blib/lib/auto/Mail/Internet/smtpsend.al) line 616
---------------- ends ------------------
OK, I'm braced for someone finding a simple typo in my code ...
Linux server (Perl 5.8.0). It reads variables - the recipient, the
outbound mail server and so on - from an XML file into a hash.
Using the variables in the hash causes errors in Mail::Internet; using
equivalent variables from a hash created from data in the program does
not cause the same error. Odder still, the error doesn't occur at all
when I run the same program under ActiveState Perl in Windows.
Can someone help? Firstly I'm at a loss to understand why this might
be; secondly I've run out of ideas for debugging the thing.
The program below simulates the reading of the XML through the use of
__DATA__; it builds the Mail::Internet structures $header and $mail; it
then executes the smtp send using first a structure built in the program
itself ($G_server) and then the XML-derived structure ($g_server). The
program even checks that the corresponding elements in $g_server and
$G_server are the same ...
----------- sample program ------------
#! /usr/bin/perl
use strict;
use warnings;
use Mail::Internet;
use Mail::Header;
use XML::Simple;
my @data = <DATA>;
my $xml = XMLin(join (' ',@data));
my %g_server;
$g_server{adminuser} = $xml -> {adminuser};
$g_server{smtpserver} = $xml -> {smtpserver};
$g_server{localuser} = $xml -> {localuser};
my %G_server = (localuser=>'(e-mail address removed)',
adminuser=>'(e-mail address removed)',
smtpserver=>'smtp.bt.net');
my @message = ("Line 1\n","Line 2");
print ( $g_server{localuser} eq $G_server{localuser} ?
"localuser same\n" : "localuser different\n");
print ( $g_server{adminuser} eq $G_server{adminuser} ?
"adminuser same\n" : "adminuser different\n");
print ( $g_server{smtpserver} eq $G_server{smtpserver} ?
"smtpserver same\n" : "smtpserver different\n");
my $header = Mail::Header->new( ["From:$g_server{localuser}",
"Sender:$g_server{localuser}",
"To:$g_server{adminuser}",
"Subject:Testing"] );
my $mail = Mail::Internet->new(Header=>$header,Body=>\@message);
my @recipients;
print "Sending with G_server variables\n";
@recipients = $mail->smtpsend(Host=>$G_server{smtpserver},
MailFrom=>$G_server{localuser},
To=>$G_server{adminuser});
print "Mail sent to @recipients\n";
print "Sending with g_server variables\n";
@recipients = $mail->smtpsend(Host=>$g_server{smtpserver},
MailFrom=>$g_server{localuser},
To=>$g_server{adminuser});
print "Mail sent to @recipients\n";
__DATA__
<nfbserver>
<adminuser>[email protected]</adminuser>
<smtpserver>smtp.bt.net</smtpserver>
<localuser>[email protected]</localuser>
</nfbserver>
----------------- output under Linux ----------------
[nfb@neptune nfb]$ ./tryit.pl
localuser same
adminuser same
smtpserver same
Sending with G_server variables
Mail sent to (e-mail address removed)
Sending with g_server variables
Unrecognised line: (e-mail address removed) at blib/lib/Mail/Internet.pm
(autosplit into blib/lib/auto/Mail/Internet/smtpsend.al) line 616
---------------- ends ------------------
OK, I'm braced for someone finding a simple typo in my code ...