SMTP outgoing Mail setup on linux using perl
I am facing problem开发者_Python百科 in sending mail using perl. When I put following command: my $smtp = Net::SMTP->new($ServerName, Debug => 0); where $ServerName="localhost" . the $smtp is not set. It is null. Can anybody tell me the reason why it is not set appropriately . Since the same script is running on my other linux server.
Help is truly appreciated.
Thanks DD
Net::SMTP
, it appears, has rather underwhelming error handling.
The best you can do is:
my $smtp = Net::SMTP->new($ServerName)
or die "Unable to connect to SMTP server '$ServerName'";
Even passing Debug => 1
appears to do nothing when it can't create the object.
There hasn't been a new release of libnet (which includes Net::SMTP) in over three years. There is a developer release from May 2010 which does appear to have some improvements: it documents:
On failure undef will be returned and $@ will contain the reason for the failure.
(The most recent proper release does not do this.)
If you're willing to try installing the developer release, you can improve your code to:
my $smtp = Net::SMTP->new($ServerName)
or die "Unable to connect to SMTP server '$ServerName': $@";
Possible reasons your connection is failing:
- $ServerName not a valid host name
- No SMTP service running on $ServerName
- The server doesn't like the standard greeting,
localhost.localdomain
. PassHello => 'your.fully.qualified.host.name'
to the constructor.
You can try connecting to the SMTP server on the command line, on the host where you're trying to run this script:
$ telnet smtp.example.com
EHLO localhost.localdomain
quit
Have you tried to enable debugging?
$smtp = Net::SMTP->new(
Host => 'mailhost',
Hello => 'my.mail.domain',
Timeout => 30,
Debug => 1,
);
Then have a look at what the debug output says.
精彩评论