From 0802651ae943c08913aa28ce2aa139089527bced Mon Sep 17 00:00:00 2001 From: Graham Barr Date: Mon, 20 Oct 2003 18:56:15 +0000 Subject: Net::SMTP - Added Host option as an alternative way to pass host to connect to - Added ->host method to return name of connected host --- Net/SMTP.pm | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/Net/SMTP.pm b/Net/SMTP.pm index be64037..9183e70 100644 --- a/Net/SMTP.pm +++ b/Net/SMTP.pm @@ -16,7 +16,7 @@ use IO::Socket; use Net::Cmd; use Net::Config; -$VERSION = "2.26"; # $Id: //depot/libnet/Net/SMTP.pm#31 $ +$VERSION = "2.27"; # $Id: //depot/libnet/Net/SMTP.pm#32 $ @ISA = qw(Net::Cmd IO::Socket::INET); @@ -24,8 +24,14 @@ sub new { my $self = shift; my $type = ref($self) || $self; - my $host = shift if @_ % 2; - my %arg = @_; + my ($host,%arg); + if (@_ % 2) { + $host = shift ; + %arg = @_; + } else { + %arg = @_; + $host=delete $arg{Host}; + } my $hosts = defined $host ? $host : $NetConfig{smtp_hosts}; my $obj; @@ -71,6 +77,11 @@ sub new $obj; } +sub host { + my $me = shift; + ${*$me}{'net_smtp_host'}; +} + ## ## User interface methods ## @@ -570,11 +581,9 @@ known as mailhost: This is the constructor for a new Net::SMTP object. C is the name of the remote host to which an SMTP connection is required. -If C is an array reference then each value will be attempted -in turn until a connection is made. - -If C is not given, then the C specified in C -will be used. +C is optional. If C is not given then it may instead be +passed as the C option described below. If neither is given then +the C specified in C will be used. C are passed in a hash like fashion, using key and value pairs. Possible options are: @@ -583,6 +592,11 @@ B - SMTP requires that you identify yourself. This option specifies a string to pass as your mail domain. If not given a guess will be taken. +B - SMTP host to connect to. It may be a single scalar, as defined for +the C option in L, or a reference to +an array with hosts to try in turn. The L method will return the value +which was used to connect to the host. + B and B - These parameters are passed directly to IO::Socket to allow binding the socket to a local port. @@ -605,6 +619,20 @@ Example: Debug => 1, ); + # the same + $smtp = Net::SMTP->new( + Host => 'mailhost', + Hello => 'my.mail.domain' + Timeout => 30, + Debug => 1, + ); + + # Connect to the default server from Net::config + $smtp = Net::SMTP->new( + Hello => 'my.mail.domain' + Timeout => 30, + ); + =back =head1 METHODS @@ -633,6 +661,11 @@ command (or HELO if EHLO fails). Since this method is invoked automatically when the Net::SMTP object is constructed the user should normally not have to call it manually. +=item host () + +Returns the value used by the constructor, and passed to IO::Socket::INET, +to connect to the host. + =item etrn ( DOMAIN ) Request a queue run for the DOMAIN given. @@ -765,6 +798,6 @@ it under the same terms as Perl itself. =for html
-I<$Id: //depot/libnet/Net/SMTP.pm#31 $> +I<$Id: //depot/libnet/Net/SMTP.pm#32 $> =cut -- cgit v1.2.3-24-ge0c7