Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Capture smtp mailserver that responds to hello.

by shadowfox (Sexton)
on Feb 02, 2012 at 15:18 UTC ( #951463=perlquestion: print w/replies, xml ) Need Help??
shadowfox has asked for the wisdom of the Perl Monks concerning the following question:

We have a primary mailserver address that is actually 3 mailservers working in failover, so if one is down it goes to the next, etc. The problem is that it's not entirely working as intended all the time so I'd like my scripts to have a seperate backup mail server incase the first one can't be contacted. I think I've got that down, but I'd like to log which mail server actually responded after I sent my hello command and save in my logs. I thought it was suppose to be domain() but its not looking to be the case?

Error: Can't locate object method "domain" via package "smtp" (perhaps you forgot to load "smtp"?)
use strict ; use Net::SMTP ; use warnings ; use Sys::Hostname ; my $SRV = hostname ; my $MAILSRV1 = "" ; # actually, smtp2, my $MAILSRV2 = "" ; # the backup just incase. my $smtp = Net::SMTP->new($MAILSRV1, Hello => $SRV, Timeout => 30,Debu +g => 1) or print "$! \n"; if(!defined($smtp) || !($smtp)) { print "SMTP ERROR: Connection timeout\n"; my $smtp = Net::SMTP->new($MAILSRV2, Hello => $SRV, Timeou +t => 30,Debug => 1) or print "$! \n"; print "Trying backup email server to send email\n"; } else{ print "Using primary email server to send email\n" ; } $smtp->mail("sender\") ; my @emails = ("reciepiant1\", "reciepiant2\") ; my $subject = "test subject"; my $content ="test data \n") ; my $whoareu = smtp->domain() ; $smtp->to(@emails) ; $smtp->recipient(@emails) ; $smtp->data() ; $smtp->datasend("Priority: Urgent\n") ; $smtp->datasend("Importance: high\n") ; $smtp->datasend("TO: @emails\n") ; $smtp->datasend("Subject: $subject\n") ; $smtp->datasend("$content\n") ; $smtp->datasend("$whoareu\n") ; $smtp->dataend() ; $smtp->quit ; print "The mail server that responded was $whoareu \n" ; exit ;

Replies are listed 'Best First'.
Re: Capture smtp mailserver that responds to hello.
by marto (Bishop) on Feb 02, 2012 at 15:21 UTC
      Yep, that was it. I got too caught up looking for another way to do it I missed the most basic of problems.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951463]
Approved by marto
NodeReaper power washes the cellar floor

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2017-08-23 18:18 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (355 votes). Check out past polls.