Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
No such thing as a small change
 
PerlMonks  

add to MIME::Lite support for smtp tls on port 587

by swilting (Beadle)
on Sep 14, 2010 at 02:37 UTC ( #860057=perlquestion: print w/ replies, xml ) Need Help??
swilting has asked for the wisdom of the Perl Monks concerning the following question:

i re add a correct pach for MIME::Lite for most the compliance enverts the libs

[[root@r13151 ~]# diff -u MIME-Lite-3.027/lib/MIME/Lite.pm /usr/lib/p +erl5/site_perl/5.8.8/MIME/Lite.pm --- MIME-Lite-3.027/lib/MIME/Lite.pm 2009-10-10 04:04:04.000000000 ++0200 +++ /usr/lib/perl5/site_perl/5.8.8/MIME/Lite.pm 2010-09-15 18:47:00.00 +0000000 +0200 @@ -404,6 +404,8 @@ sendmail => [$SENDMAIL ? "$SENDMAIL -t -oi -oem" : undef], smtp => [], sub => [], + tls => [], + ssl => [], ); ### Boundary counter: @@ -2565,22 +2567,28 @@ if (@_) { ### args; use them just this once $method = 'send_by_' . $meth; @args = @_; - } else { ### no args; use defaults + } elsif (@_) { ### no args; use defaults $method = "send_by_$Sender"; @args = @{ $SenderArgs{$Sender} || [] }; - } - $self->verify_data if $AUTO_VERIFY; ### prevents missing p +arts! - Carp::croak "Unknown send method '$meth'" unless $self->can($ +method); - return $self->$method(@args); - } else { ### class method: - if (@_) { + } elsif (@_) { my @old = ( $Sender, @{ $SenderArgs{$Sender} } ); $Sender = $meth; $SenderArgs{$Sender} = [@_]; ### remaining args return @old; - } else { + } elsif (@_) { + $method = "send_by_$Sender"; + @args = @{ $SenderArgs{$Sender} || [] }; + } elsif (@_) { + $method = "send_by_$Sender"; + @args = @{ $SenderArgs{$Sender} || [] }; + + + $self->verify_data if $AUTO_VERIFY; ### prevents missing p +arts! + Carp::croak "Unknown send method '$meth'" unless $self->can($ +method); + return $self->$method(@args); + } else { Carp::croak "class method send must have HOW... arguments +\n"; - } + } } } @@ -2908,6 +2916,150 @@ return $self->{last_send_successful} = 1; } +sub send_by_tls { + require Net::SMTP::TLS; + require Net::SMTP_auth; + my ($self,$hostname,%args) = @_; + # We may need the "From:" and "To:" headers to pass to the + # SMTP mailer also. + $self->{last_send_successful}=0; + + my @hdr_to = extract_only_addrs( scalar $self->get('To') ); + if ($AUTO_CC) { + foreach my $field (qw(Cc Bcc)) { + push @hdr_to, extract_only_addrs($_) for $self->get($fiel +d); + } + } + Carp::croak "send_by_smtp: nobody to send to for host '$hostname'?! +\n" + unless @hdr_to; + + $args{To} ||= \@hdr_to; + $args{From} ||= extract_only_addrs( scalar $self->get('Return-Pat +h') ); + $args{From} ||= extract_only_addrs( scalar $self->get('From') ) ; + + # Create SMTP client. + # MIME::Lite::SMTP is just a wrapper giving a print method + # to the SMTP object. + + my %opts = __opts(\%args, @_net_smtp_opts); + my $smtp = MIME::Lite::SMTP::TLS->new( $hostname, %opts ) + or Carp::croak "SMTP Failed to connect to mail server: $!\n"; + + # Possibly authenticate + if ( defined $args{AuthUser} and defined $args{AuthPass} + and !$args{NoAuth} ) + { + if ($smtp->supports('AUTH',500,["Command unknown: 'AUTH'"])) +{ + $smtp->auth( $args{AuthUser}, $args{AuthPass} ) + or die "SMTP auth() command failed: $!\n" + . $smtp->message . "\n"; + } else { + die "SMTP auth() command not supported on $hostname\n"; + } + } + + # Send the mail command + %opts = __opts( \%args, @_mail_opts); + $smtp->mail( $args{From}, %opts ? \%opts : () ) + or die "SMTP mail() command failed: $!\n" + . $smtp->message . "\n"; + + # Send the recipients command + %opts = __opts( \%args, @_recip_opts); + $smtp->recipient( @{ $args{To} }, %opts ? \%opts : () ) + or die "SMTP recipient() command failed: $!\n" + . $smtp->message . "\n"; + + # Send the data + $smtp->data() + or die "SMTP data() command failed: $!\n" + . $smtp->message . "\n"; + $self->print_for_smtp($smtp); + + # Finish the mail + $smtp->dataend() + or Carp::croak "Net::CMD (Net::SMTP) DATAEND command failed.\n" + . "Last server message was:" + . $smtp->message + . "This probably represents a problem with newline encoding "; + + # terminate the session + $smtp->quit; + + return $self->{last_send_successful} = 1; +} +sub send_by_ssl { + require Net::SMTP::SSL; + require Net::SMTP_auth; + my ($self,$hostname,%args) = @_; + # We may need the "From:" and "To:" headers to pass to the + # SMTP mailer also. + $self->{last_send_successful}=0; + + my @hdr_to = extract_only_addrs( scalar $self->get('To') ); + if ($AUTO_CC) { + foreach my $field (qw(Cc Bcc)) { + push @hdr_to, extract_only_addrs($_) for $self->get($fiel +d); + } + } + Carp::croak "send_by_smtp: nobody to send to for host '$hostname'?! +\n" + unless @hdr_to; + + $args{To} ||= \@hdr_to; + $args{From} ||= extract_only_addrs( scalar $self->get('Return-Pat +h') ); + $args{From} ||= extract_only_addrs( scalar $self->get('From') ) ; + + # Create SMTP client. + # MIME::Lite::SMTP is just a wrapper giving a print method + # to the SMTP object. + + my %opts = __opts(\%args, @_net_smtp_opts); + my $smtp = MIME::Lite::SMTP::SSL->new( $hostname, %opts ) + or Carp::croak "SMTP Failed to connect to mail server: $!\n"; + + # Possibly authenticate + if ( defined $args{AuthUser} and defined $args{AuthPass} + and !$args{NoAuth} ) + { + if ($smtp->supports('AUTH',500,["Command unknown: 'AUTH'"])) +{ + $smtp->auth( $args{AuthUser}, $args{AuthPass} ) + or die "SMTP auth() command failed: $!\n" + . $smtp->message . "\n"; + } else { + die "SMTP auth() command not supported on $hostname\n"; + } + } + + # Send the mail command + %opts = __opts( \%args, @_mail_opts); + $smtp->mail( $args{From}, %opts ? \%opts : () ) + or die "SMTP mail() command failed: $!\n" + . $smtp->message . "\n"; + + # Send the recipients command + %opts = __opts( \%args, @_recip_opts); + $smtp->recipient( @{ $args{To} }, %opts ? \%opts : () ) + or die "SMTP recipient() command failed: $!\n" + . $smtp->message . "\n"; + + # Send the data + $smtp->data() + or die "SMTP data() command failed: $!\n" + . $smtp->message . "\n"; + $self->print_for_smtp($smtp); + + # Finish the mail + $smtp->dataend() + or Carp::croak "Net::CMD (Net::SMTP) DATAEND command failed.\n" + . "Last server message was:" + . $smtp->message + . "This probably represents a problem with newline encoding "; + + # terminate the session + $smtp->quit; + + return $self->{last_send_successful} = 1; +} =item send_by_testfile FILENAME @@ -3125,6 +3277,90 @@ . "This probably represents a problem with newl +ine encoding " ); } +#============================================================ + +package MIME::Lite::SMTP::TLS; + +#============================================================ +# This class just adds a print() method to Net::SMTP. +# Notice that we don't use/require it until it's needed! + +use strict; +use vars qw( @ISA ); +@ISA = qw(Net::SMTP::TLS); + +# some of the below is borrowed from Data::Dumper +my %esc = ( "\a" => "\\a", + "\b" => "\\b", + "\t" => "\\t", + "\n" => "\\n", + "\f" => "\\f", + "\r" => "\\r", + "\e" => "\\e", + ); + +sub _hexify { + local $_ = shift; + my @split = m/(.{1,16})/gs; + foreach my $split (@split) { + ( my $txt = $split ) =~ s/([\a\b\t\n\f\r\e])/$esc{$1}/sg; + $split =~ s/(.)/sprintf("%02X ",ord($1))/sge; + print STDERR "M::L >>> $split : $txt\n"; + } +} + +sub print { + my $smtp = shift; + $MIME::Lite::DEBUG and _hexify( join( "", @_ ) ); + $smtp->datasend(@_) + or Carp::croak( "Net::CMD (Net::SMTP) DATASEND command failed +.\n" + . "Last server message was:" + . $smtp->message + . "This probably represents a problem with new +line encoding " ); +} + +#============================================================ + +package MIME::Lite::SMTP::SSL; + +#============================================================ +# This class just adds a print() method to Net::SMTP. +# Notice that we don't use/require it until it's needed! + +use strict; +use vars qw( @ISA ); +@ISA = qw(Net::SMTP::SSL); + +# some of the below is borrowed from Data::Dumper +my %esc = ( "\a" => "\\a", + "\b" => "\\b", + "\t" => "\\t", + "\n" => "\\n", + "\f" => "\\f", + "\r" => "\\r", + "\e" => "\\e", + ); + +sub _hexify { + local $_ = shift; + my @split = m/(.{1,16})/gs; + foreach my $split (@split) { + ( my $txt = $split ) =~ s/([\a\b\t\n\f\r\e])/$esc{$1}/sg; + $split =~ s/(.)/sprintf("%02X ",ord($1))/sge; + print STDERR "M::L >>> $split : $txt\n"; + } +} + +sub print { + my $smtp = shift; + $MIME::Lite::DEBUG and _hexify( join( "", @_ ) ); + $smtp->datasend(@_) + or Carp::croak( "Net::CMD (Net::SMTP) DATASEND command failed +.\n" + . "Last server message was:" + . $smtp->message + . "This probably represents a problem with new +line encoding " ); +} + #============================================================

it's work perfectly with the constucteur send modified but the mail not send First , my config of postfix its ok its perfectly stable . i send mail on port 587 . thank you for your example but I respect the habits of PERL %opts does contain the user name and password . There is an old article about a port problem

http://prlmnks.org/html/569255.html

I think I am a victim of problem board and MIME::Lite takes into account the difficulty of the issue of port mail or this not send

Comment on add to MIME::Lite support for smtp tls on port 587
Download Code
Re: add to MIME::Lite support for smtp tls on port 587
by Khen1950fx (Canon) on Sep 14, 2010 at 06:31 UTC
    It doesn't work perfectly. You need to reduce your posts to a minimum runnable snippet that can reproduce your error.

    Port 25 is the default smtp port. To use 587, you'll need to mention it in the source of a form such as:

    PeerPort => $arg{Port} || 'smtp(587)',

    In the script, mention it in the constructor like

     Port => 587,

    or

     PeerPort => 587,

      when I indicate Port => 587 in the constructor. the mail is sent through the port 25 when the same

      i modified the patch .I can reproduce the error. I integrated the new lib in perlwebmail of jaos, and mail out each time with port 25

      [root@r13151 ~]# diff -r /usr/lib/perl5/vendor_perl/5.8.8/MIME/Lite.pm + MIME-Lite-3.027/lib/MIME/Lite.pm 347c347 < $VERSION = '3.025'; --- > $VERSION = '3.027'; 407d406 < tls => [], 440c439 < if ( !$PARANOID and eval "require MIME::Types; MIME::Types->VERSION( +1.004);" ) { --- > if ( !$PARANOID and eval "require MIME::Types; MIME::Types->VERSION( +1.28);" ) { 2569,2570c2568 < } < if (@_) { ### no args; use defaults --- > } else { ### no args; use defaults 2573,2575d2570 < } else { < $method = 'send_by_smtp_' . $meth; < @args = @{ $SenderArgs{$Sender} || [] }; 2844,2902d2838 < sub send_by_smtp_tls { < require Net::SMTP::TLS; < my ($self,$hostname,%args) = @_; < # We may need the "From:" and "To:" headers to pass to the < # SMTP mailer also. < $self->{last_send_successful}=0; < < my @hdr_to = extract_only_addrs( scalar $self->get('To') ); < if ($AUTO_CC) { < foreach my $field (qw(Cc Bcc)) { < push @hdr_to, extract_only_addrs($_) for $self->get($fie +ld); < } < } < Carp::croak "send_by_smtp: nobody to send to for host '$hostname'? +!\n" < unless @hdr_to; < < $args{To} ||= \@hdr_to; < $args{From} ||= extract_only_addrs( scalar $self->get('Return-Pa +th') ); < $args{From} ||= extract_only_addrs( scalar $self->get('From') ) +; < < # Create SMTP client. < # MIME::Lite::SMTP is just a wrapper giving a print method < # to the SMTP object. < < my %opts = __opts(\%args, @_net_smtp_opts); < my $smtp = MIME::Lite::SMTP::TLS->new( $hostname, %opts ) < or Carp::croak "SMTP Failed to connect to mail server: $!\n"; < < # Send the mail command < %opts = __opts( \%args, @_mail_opts); < $smtp->mail( $args{From}, %opts ? \%opts : () ) < or die "SMTP mail() command failed: $!\n" < . $smtp->message . "\n"; < < # Send the recipients command < %opts = __opts( \%args, @_recip_opts); < $smtp->to( @{ $args{To} }, %opts ? \%opts : () ) < or die "SMTP recipient() command failed: $!\n" < . $smtp->message . "\n"; < < # Send the data < $smtp->data < or die "SMTP data() command failed: $!\n" < . $smtp->message . "\n"; < $self->datasend( eval {print_for_smtp($smtp)}); < < # Finish the mail < $smtp->dataend() < or Carp::croak "Net::CMD (Net::SMTP) DATAEND command failed.\n +" < . "Last server message was:" < . $smtp->message < . "This probably represents a problem with newline encoding "; < < # terminate the session < $smtp->quit; < < return $self->{last_send_successful} = 1; < } < 2930a2867 > 2974a2912,2942 > =item send_by_testfile FILENAME > > I<Instance method.> > Print message to a file (namely FILENAME), which will default to > mailer.testfile > If file exists, message will be appended. > > =cut > > sub send_by_testfile { > my $self = shift; > > ### Use the default filename... > my $filename = 'mailer.testfile'; > > if ( @_ == 1 and !ref $_[0] ) { > ### Use the given filename if given... > $filename = shift @_; > Carp::croak "no filename given to send_by_testfile" unless $file +name; > } > > ### Do it: > local *FILE; > open FILE, ">> $filename" or Carp::croak "open $filename: $!\n"; > $self->print( \*FILE ); > close FILE; > my $return = ( ( $? >> 8 ) ? undef: 1 ); > > return $self->{last_send_successful} = $return; > } > 3025d2992 < require Net::SMTP::TLS, 3164,3204d3130 < package MIME::Lite::SMTP::TLS; < < #============================================================ < # This class just adds a print() method to Net::SMTP. < # Notice that we don't use/require it until it's needed! < < use strict; < use vars qw( @ISA ); < @ISA = qw(Net::SMTP::TLS); < < # some of the below is borrowed from Data::Dumper < my %esc = ( "\a" => "\\a", < "\b" => "\\b", < "\t" => "\\t", < "\n" => "\\n", < "\f" => "\\f", < "\r" => "\\r", < "\e" => "\\e", < ); < < sub _hexify { < local $_ = shift; < my @split = m/(.{1,16})/gs; < foreach my $split (@split) { < ( my $txt = $split ) =~ s/([\a\b\t\n\f\r\e])/$esc{$1}/sg; < $split =~ s/(.)/sprintf("%02X ",ord($1))/sge; < print STDERR "M::L >>> $split : $txt\n"; < } < } < < sub print { < my $smtp = shift; < $MIME::Lite::DEBUG and _hexify( join( "", @_ ) ); < $smtp->datasend(@_) < or Carp::croak( "Net::CMD (Net::SMTP) DATASEND command faile +d.\n" < . "Last server message was:" < . $smtp->message < . "This probably represents a problem with new +line encoding " ); < } < #============================================================ < 3717c3643 < Version: 3.01_06 (Dev Test Release) --- > Version: 3.027

        despite all my efforts, I can not pass the emails through port 587

        Yet in the constructor of the method I said port 587 . this may be a problem with my postfix . all suggestions are welcome to help me

        Port 587 requires authentication. Did you give a username and password under %opts? The example from Net::SMTP::TLS:
        #!/usr/bin/perl use strict; use warnings; use Net::SMTP::TLS; my $mailer = new Net::SMTP::TLS( 'your.mail.host', Hello => 'some.host.name', Port => 587, User => 'emailuser', Password=> 'password'); $mailer->mail('emailuser@your.mail.host'); $mailer->to('someonecool@somewhere.else'); $mailer->data; $mailer->datasend("Sent thru TLS!"); $mailer->dataend; $mailer->quit;
        First, note the use of Hello. It's the hostname used in the EHLO command.

        Second, if you are using Postfix, then you'll need to check the config. You might need to specify port 587. For example, find your config and list your transport something like:

        transport=Net::SMTP::TLS user@exmple.com Password 12345 Port 587
        Check the documentation of Postfix for more info.
add to MIME::Lite support for smtp tls and ssl on port 587 465
by swilting (Beadle) on Sep 16, 2010 at 20:07 UTC

    i re add my patch correct if the blow

    ~]$ diff -u Desktop/MIME-Lite-3.027/lib/MIME/Lite.pm /usr/lib/perl5/s +ite_perl/5.8.8/MIME/Lite.pm --- Desktop/MIME-Lite-3.027/lib/MIME/Lite.pm 2009-10-10 04:04:04.00 +0000000 +0200 +++ /usr/lib/perl5/site_perl/5.8.8/MIME/Lite.pm 2010-09-16 20:11:16.00 +0000000 +0200 @@ -404,6 +404,8 @@ sendmail => [$SENDMAIL ? "$SENDMAIL -t -oi -oem" : undef], smtp => [], sub => [], + tls => [], + ssl => [], ); ### Boundary counter: @@ -2562,25 +2564,23 @@ if ( ref($self) ) { ### instance method: my ( $method, @args ); - if (@_) { ### args; use them just this once - $method = 'send_by_' . $meth; + if (@_) { ### no args; use defaults + $method = 'send_by_'.$meth; @args = @_; - } else { ### no args; use defaults + } elsif (@_) { + my @old = ( $Sender, @{ $SenderArgs{$Sender} } ); + $Sender = $meth; + $SenderArgs{$Sender} = [@_]; ### remaining args + return @old; + } elsif (@_) { $method = "send_by_$Sender"; @args = @{ $SenderArgs{$Sender} || [] }; - } + } $self->verify_data if $AUTO_VERIFY; ### prevents missing p +arts! Carp::croak "Unknown send method '$meth'" unless $self->can($ +method); return $self->$method(@args); - } else { ### class method: - if (@_) { - my @old = ( $Sender, @{ $SenderArgs{$Sender} } ); - $Sender = $meth; - $SenderArgs{$Sender} = [@_]; ### remaining args - return @old; - } else { + } else { Carp::croak "class method send must have HOW... arguments +\n"; - } } } @@ -2829,7 +2829,7 @@ my @_mail_opts = qw( Size Return Bits Transaction Envelope ); my @_recip_opts = qw( SkipBad ); my @_net_smtp_opts = qw( Hello LocalAddr LocalPort Timeout - Port ExactAddresses Debug ); + Port User Password ExactAddresses Debug ); # internal: qw( NoAuth AuthUser AuthPass To From Host); sub __opts { @@ -2872,7 +2872,7 @@ if ($smtp->supports('AUTH',500,["Command unknown: 'AUTH'"])) +{ $smtp->auth( $args{AuthUser}, $args{AuthPass} ) or die "SMTP auth() command failed: $!\n" - . $smtp->message . "\n"; + . $smtp . "\n"; } else { die "SMTP auth() command not supported on $hostname\n"; } @@ -2893,14 +2893,14 @@ # Send the data $smtp->data() or die "SMTP data() command failed: $!\n" - . $smtp->message . "\n"; + . $smtp . "\n"; $self->print_for_smtp($smtp); # Finish the mail $smtp->dataend() or Carp::croak "Net::CMD (Net::SMTP) DATAEND command failed.\n" . "Last server message was:" - . $smtp->message + . $smtp . "This probably represents a problem with newline encoding "; # terminate the session @@ -2908,6 +2908,121 @@ return $self->{last_send_successful} = 1; } +sub send_by_tls { + require Net::SMTP::TLS; + my ($self,$hostname,%args) = @_; + # We may need the "From:" and "To:" headers to pass to the + # SMTP mailer also. + $self->{last_send_successful}=0; + + my @hdr_to = extract_only_addrs( scalar $self->get('To') ); + if ($AUTO_CC) { + foreach my $field (qw(Cc Bcc)) { + push @hdr_to, extract_only_addrs($_) for $self->get($fiel +d); + } + } + Carp::croak "send_by_smtp: nobody to send to for host '$hostname'?! +\n" + unless @hdr_to; + + $args{To} ||= \@hdr_to; + $args{From} ||= extract_only_addrs( scalar $self->get('Return-Pat +h') ); + $args{From} ||= extract_only_addrs( scalar $self->get('From') ) ; + + # Create SMTP client. + # MIME::Lite::SMTP is just a wrapper giving a print method + # to the SMTP object. + + my %opts = __opts(\%args, @_net_smtp_opts); + my $smtp = MIME::Lite::SMTP::TLS->new( $hostname, %opts ) + or Carp::croak "SMTP Failed to connect to mail server: $!\n"; + + # Send the mail command + %opts = __opts( \%args, @_mail_opts); + $smtp->mail( $args{From}, %opts ? \%opts : () ) + or die "SMTP mail() command failed: $!\n" + . $smtp . "\n"; + + # Send the recipients command + %opts = __opts( \%args, @_recip_opts); + $smtp->to( @{ $args{To} }, %opts ? \%opts : () ) + or die "SMTP recipient() command failed: $!\n" + . $smtp . "\n"; + + # Send the data + $smtp->data() + or die "SMTP data() command failed: $!\n" + . $smtp . "\n"; + $self->print_for_smtp($smtp); + + # Finish the mail + $smtp->dataend() + or Carp::croak "Net::CMD (Net::SMTP) DATAEND command failed.\n" + . "Last server message was:" + . $smtp . "This probably represents a problem with newline enco +ding "; + + # terminate the session + $smtp->quit; + + return $self->{last_send_successful} = 1; +} +sub send_by_ssl { + require Net::SMTP::SSL; + my ($self,$hostname,%args) = @_; + # We may need the "From:" and "To:" headers to pass to the + # SMTP mailer also. + $self->{last_send_successful}=0; + + my @hdr_to = extract_only_addrs( scalar $self->get('To') ); + if ($AUTO_CC) { + foreach my $field (qw(Cc Bcc)) { + push @hdr_to, extract_only_addrs($_) for $self->get($fiel +d); + } + } + Carp::croak "send_by_smtp: nobody to send to for host '$hostname'?! +\n" + unless @hdr_to; + + $args{To} ||= \@hdr_to; + $args{From} ||= extract_only_addrs( scalar $self->get('Return-Pat +h') ); + $args{From} ||= extract_only_addrs( scalar $self->get('From') ) ; + + # Create SMTP client. + # MIME::Lite::SMTP is just a wrapper giving a print method + # to the SMTP object. + + my %opts = __opts(\%args, @_net_smtp_opts); + my $smtp = MIME::Lite::SMTP::SSL->new( $hostname, %opts ) + or Carp::croak "SMTP Failed to connect to mail server: $!\n"; + + + # Send the mail command + %opts = __opts( \%args, @_mail_opts); + $smtp->mail( $args{From}, %opts ? \%opts : () ) + or die "SMTP mail() command failed: $!\n" + . $smtp . "\n"; + + # Send the recipients command + %opts = __opts( \%args, @_recip_opts); + $smtp->to( @{ $args{To} }, %opts ? \%opts : () ) + or die "SMTP recipient() command failed: $!\n" + . $smtp . "\n"; + + # Send the data + $smtp->data() + or die "SMTP data() command failed: $!\n" + . $smtp->message . "\n"; + $self->print_for_smtp($smtp); + + # Finish the mail + $smtp->dataend() + or Carp::croak "Net::CMD (Net::SMTP) DATAEND command failed.\n" + . "Last server message was:" + . $smtp . "This probably represents a problem with newline enco +ding "; + + # terminate the session + $smtp->quit; + + return $self->{last_send_successful} = 1; +} =item send_by_testfile FILENAME @@ -3121,10 +3236,92 @@ $smtp->datasend(@_) or Carp::croak( "Net::CMD (Net::SMTP) DATASEND command failed +.\n" . "Last server message was:" - . $smtp->message + . $smtp . "This probably represents a problem with newl +ine encoding " ); } +#============================================================ + +package MIME::Lite::SMTP::TLS; + +#============================================================ +# This class just adds a print() method to Net::SMTP. +# Notice that we don't use/require it until it's needed! + +use strict; +use vars qw( @ISA ); +@ISA = qw(Net::SMTP::TLS); + +# some of the below is borrowed from Data::Dumper +my %esc_tls = ( "\a" => "\\a", + "\b" => "\\b", + "\t" => "\\t", + "\n" => "\\n", + "\f" => "\\f", + "\r" => "\\r", + "\e" => "\\e", + ); + +sub _hexify { + local $_ = shift; + my @split = m/(.{1,16})/gs; + foreach my $split (@split) { + ( my $txt = $split ) =~ s/([\a\b\t\n\f\r\e])/$esc_tls{$1}/sg; + $split =~ s/(.)/sprintf("%02X ",ord($1))/sge; + print STDERR "M::L >>> $split : $txt\n"; + } +} + +sub print { + my $smtp = shift; + $MIME::Lite::DEBUG and _hexify( join( "", @_ ) ); + $smtp->datasend(@_) + or Carp::croak( "Net::CMD (Net::SMTP) DATASEND command failed +.\n" + . "Last server message was:" + . $smtp . "This probably represents a problem w +ith newline encoding " ); +} + +#============================================================ + +package MIME::Lite::SMTP::SSL; + +#============================================================ +# This class just adds a print() method to Net::SMTP. +# Notice that we don't use/require it until it's needed! + +use strict; +use vars qw( @ISA ); +@ISA = qw(Net::SMTP::SSL); + +# some of the below is borrowed from Data::Dumper +my %esc_ssl = ( "\a" => "\\a", + "\b" => "\\b", + "\t" => "\\t", + "\n" => "\\n", + "\f" => "\\f", + "\r" => "\\r", + "\e" => "\\e", + ); + +sub _hexify { + local $_ = shift; + my @split = m/(.{1,16})/gs; + foreach my $split (@split) { + ( my $txt = $split ) =~ s/([\a\b\t\n\f\r\e])/$esc_ssl{$1}/sg; + $split =~ s/(.)/sprintf("%02X ",ord($1))/sge; + print STDERR "M::L >>> $split : $txt\n"; + } +} + +sub print { + my $smtp = shift; + $MIME::Lite::DEBUG and _hexify( join( "", @_ ) ); + $smtp->datasend(@_) + or Carp::croak( "Net::CMD (Net::SMTP) DATASEND command failed +.\n" + . "Last server message was:" + . $smtp . "This probably represents a problem w +ith newline encoding " ); +} + #============================================================

    I find myself with an error during authentication SASL LOGIN an error that I can not explain. I use perl correctly . my exemple to not work authentifications is

    #!/usr/bin/perl -w use Getopt::Long; use MIME::Lite; use strict; use warnings; my $cc; my $bcc; my $msg; GetOptions( 'cc=s' => \$cc, 'bcc=s' => \$bcc, ); my( $from, $to, $subject ) = @ARGV; $msg = MIME::Lite->new ( From => $from, To => $to, Subject => $subject ); $msg->send('tls','mail.fakessh.eu', Hello => 'mail.fakessh.eu', Port => "587", User => "fakessh\@fakessh.eu" , Password => "***************" , Debug => 4 );

    thanks for more return

      Please, boil it down to a succinct case...
      and stop posting as new threads that which makes sense only as followups to your earlier nodes!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-04-21 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls