Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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 = "smtp1.domain.com" ; # actually smtp1.domain.com, smtp2 +.domain.com, smtp3.domain.com my $MAILSRV2 = "backup.domain.com" ; # 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\@domain.com") ; my @emails = ("reciepiant1\@domain.com", "reciepiant2\@domain.com") ; 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 ;

Comment on Capture smtp mailserver that responds to hello.
Select or Download Code
Re: Capture smtp mailserver that responds to hello.
by marto (Chancellor) 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.

      Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951463]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-04-20 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls