开发者

SMTP outgoing Mail setup on linux using perl

开发者 https://www.devze.com 2023-01-23 17:21 出处:网络
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 se

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. Pass Hello => '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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号