diff options
author | Graham Barr <gbarr@pobox.com> | 2003-10-20 18:56:15 +0000 |
---|---|---|
committer | Graham Barr <gbarr@pobox.com> | 2003-10-20 18:56:15 +0000 |
commit | 0802651ae943c08913aa28ce2aa139089527bced (patch) | |
tree | 89f446277e90381553b5b9a7b76b5a38eb8675c2 | |
parent | 6a671f9cc89c63c5e9f7c8ad66dcbc916f387ff7 (diff) | |
download | perl-libnet-0802651ae943c08913aa28ce2aa139089527bced.tar.gz |
Net::SMTP
- Added Host option as an alternative way to pass host to connect to - Added ->host method to return name of connected host
-rw-r--r-- | Net/SMTP.pm | 51 |
1 files 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<HOST> is the name of the remote host to which an SMTP connection is required. -If C<HOST> is an array reference then each value will be attempted -in turn until a connection is made. - -If C<HOST> is not given, then the C<SMTP_Host> specified in C<Net::Config> -will be used. +C<HOST> is optional. If C<HOST> is not given then it may instead be +passed as the C<Host> option described below. If neither is given then +the C<SMTP_Hosts> specified in C<Net::Config> will be used. C<OPTIONS> are passed in a hash like fashion, using key and value pairs. Possible options are: @@ -583,6 +592,11 @@ B<Hello> - 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<Host> - SMTP host to connect to. It may be a single scalar, as defined for +the C<PeerAddr> option in L<IO::Socket::INET>, or a reference to +an array with hosts to try in turn. The L</host> method will return the value +which was used to connect to the host. + B<LocalAddr> and B<LocalPort> - 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 <hr> -I<$Id: //depot/libnet/Net/SMTP.pm#31 $> +I<$Id: //depot/libnet/Net/SMTP.pm#32 $> =cut |