*** Net.pm.orig 2013-02-16 18:10:54.000000000 -0500 --- Net.pm 2013-05-22 09:16:32.000000000 -0400 *************** *** 303,308 **** --- 303,319 ---- } } + # Make sure we can load Net::SMTP::TLS + if( $TWiki::cfg{SMTP}{UseTLS} ) { + eval { + require Net::SMTP::TLS; + }; + if( $@ ) { + $this->{session}->writeWarning( "SMTP/TLS not available: $@" ) + if ($this->{session}); + } + } + if( !$handler && $TWiki::cfg{MailProgram} ) { $handler = \&_sendEmailBySendmail; } *************** *** 500,525 **** } my $smtp = 0; ! if( $this->{HELLO_HOST} ) { ! $smtp = Net::SMTP->new( $this->{MAIL_HOST}, ! Hello => $this->{HELLO_HOST}, ! Debug => $TWiki::cfg{SMTP}{Debug} || 0 ); } else { ! $smtp = Net::SMTP->new( $this->{MAIL_HOST}, ! Debug => $TWiki::cfg{SMTP}{Debug} || 0 ); } - my $status = ''; - my $mess = "ERROR: Can't send mail using Net::SMTP. "; - die $mess."Can't connect to '$this->{MAIL_HOST}'" unless $smtp; - - if( $TWiki::cfg{SMTP}{Username} ) { - $smtp->auth($TWiki::cfg{SMTP}{Username}, $TWiki::cfg{SMTP}{Password}); - } - $smtp->mail( $from ) || die $mess.$smtp->message; - $smtp->to( @to, { SkipBad => 1 } ) || die $mess.$smtp->message; - $smtp->data( $text ) || die $mess.$smtp->message; - $smtp->dataend() || die $mess.$smtp->message; - $smtp->quit(); } 1; --- 511,609 ---- } my $smtp = 0; ! ! # Now we establish our connection to the server ! ! # If we have 'UseTLS' set, we will use Net::SMTP::TLS to send the message ! if( $TWiki::cfg{SMTP}{UseTLS} ){ ! ! # If we configured a HELLO_HOST, lets use it ! if( $this->{HELLO_HOST} ) { ! ! # If we configured a username, we need to use it here ! if( $TWiki::cfg{SMTP}{Username} && $TWiki::cfg{SMTP}{Password} ) { ! $smtp = Net::SMTP::TLS->new( ! $this->{MAIL_HOST}, ! Hello => $this->{HELLO_HOST}, ! User => $TWiki::cfg{SMTP}{Username}, ! Password => $TWiki::cfg{SMTP}{Password} ); ! ! # We did not provide a username, so setup the TLS connection a little differently ! } else { ! $smtp = Net::SMTP::TLS->new( ! $this->{MAIL_HOST}, ! Hello => $this->{HELLO_HOST} ); ! } ! ! # We did not configure a HELLO_HOST ! } else { ! ! # If we configured a username, we need to use it here ! if( $TWiki::cfg{SMTP}{Username} && $TWiki::cfg{SMTP}{Password} ) { ! $smtp = Net::SMTP::TLS->new( ! $this->{MAIL_HOST}, ! User => $TWiki::cfg{SMTP}{Username}, ! Password => $TWiki::cfg{SMTP}{Password} ); ! ! # We did not provide a username, so setup the TLS connection a little differently ! } else { ! $smtp = Net::SMTP::TLS->new( $this->{MAIL_HOST} ); ! } ! } ! ! die "ERROR: Can't send mail using Net::SMTP::TLS. Can't connect to '$this->{MAIL_HOST}'" unless $smtp; ! ! # Now that we have a connection established, let's send the message ! # Net::SMTP::TLS uses a slighty different mechanisms than Net::SMTP ! # That is why we have this piece included here ! ! eval { ! $smtp->mail( $from ); ! $smtp->to( @to ); ! $smtp->data; ! $smtp->datasend( $text ); ! $smtp->dataend(); ! $smtp->quit(); ! }; ! ! # Here is where we test for errors in sending the message ! if( $@ ){ ! die "ERROR: Can't send mail using Net::SMTP::TLS. ".$@; ! } ! ! # We do not have 'UseTLS' set, so we use plain Net::SMTP to send the message } else { ! # Since this is plain (non-TLS), we hold off on the AUTH part until later ! ! # If we configured a HELLO_HOST, lets use it ! if( $this->{HELLO_HOST} ) { ! $smtp = Net::SMTP->new( ! $this->{MAIL_HOST}, ! Hello => $this->{HELLO_HOST}, ! Debug => $TWiki::cfg{SMTP}{Debug} || 0 ); ! ! # We did not configure a HELLO_HOST ! } else { ! $smtp = Net::SMTP->new( ! $this->{MAIL_HOST}, ! Debug => $TWiki::cfg{SMTP}{Debug} || 0 ); ! } ! ! my $mess = "ERROR: Can't send mail using Net::SMTP. "; ! die $mess."Can't connect to '$this->{MAIL_HOST}'" unless $smtp; ! ! # Invoke the SMTP AUTH method, if we specified a Username and a Password in the configuration ! if( $TWiki::cfg{SMTP}{Username} && $TWiki::cfg{SMTP}{Password} ) { ! $smtp->auth($TWiki::cfg{SMTP}{Username}, $TWiki::cfg{SMTP}{Password}); ! } ! ! # Now we send the message, using the Net::SMTP style ! $smtp->mail( $from ) || die $mess.$smtp->message; ! $smtp->to( @to, { SkipBad => 1 } ) || die $mess.$smtp->message; ! $smtp->data( $text ) || die $mess.$smtp->message; ! $smtp->dataend() || die $mess.$smtp->message; ! $smtp->quit(); } } 1;