in reply to Re: instantiating an smtp object
in thread instantiating an smtp object

slightly injured, so terse. this is output with failed assumptions

host is www.1and1.com $ENV{USER} does not exists or is not defined. ... Net::SMTP fatal error: Unable to connect to 'www.1and1.com'. A connect +ion attemp t failed because the connected party did not properly respond after a +period of time, or established connection failed because connected host has fail +ed to resp ond. at (eval 35) line 3. eval ' use Net::SMTP; my $smtp = Net::SMTP->new(Host => $host, Debug => 2) or croak "Unable to connect to \'$host\'. $!"; $smtp->mail($ENV{USER}); $smtp->to($phone); $smtp->data(); $smtp->datasend("From: $ENV{USER}\\n"); $smtp->datasend("Subject: This is your map link\\n"); $smtp->datasend("\\n"); $smtp->datasend($link); $smtp->dataend(); $smtp->quit(); ;' called at alpaca4.pl line 27 main::email_link('3um671.html') called at alpaca4.pl line 12 at alpaca4.pl line 42. main::email_link('3um671.html') called at alpaca4.pl line 12 ## and then this one is the right smtp address host is smtp.1and1.com Net::SMTP fatal error: Unable to connect to 'smtp.1and1.com'. A connec +tion attem pt failed because the connected party did not properly respond after a + period of time, or established connection failed because connected host has fai +led to res pond. at (eval 35) line 3. eval ' use Net::SMTP; my $smtp = Net::SMTP->new(Host => $host, Debug => 2) or croak "Unable to connect to \'$host\'. $!"; $smtp->mail("myself"); $smtp->to($phone); $smtp->data(); $smtp->datasend("From: me\\n"); $smtp->datasend("Subject: This is your map link\\n"); $smtp->datasend("\\n"); $smtp->datasend($link); $smtp->dataend(); $smtp->quit(); ;' called at alpaca4.pl line 27 main::email_link('dn75w1.html') called at alpaca4.pl line 12 at alpaca4.pl line 42. main::email_link('dn75w1.html') called at alpaca4.pl line 12

Called 1and1. Port should be 587. Encryption should be TLS. I couldn't understand the alphanumeric for 'Larry' as pronounced by someone from India, but we worked it out because I could keep on asking questions.

Replies are listed 'Best First'.
Re^3: instantiating an smtp object
by $h4X4_|=73}{ (Monk) on Jun 07, 2016 at 09:04 UTC

    For TLS you can try Net::SMTP::TLS and take eval out. since its a bad idea to use it with Net::SMTP.

    #!/usr/bin/perl -w use strict; use 5.010; use lib "template_stuff"; use html3; sub rndStr{ join'', @_[ map{ rand @_ } 1 .. shift ] } my $new_name = rndStr( 5, 'a'..'z', 1..9); my $ref_to_name = \$new_name; my $return_page = create_page($ref_to_name); say "page is $return_page"; email_link($return_page); sub email_link{ use strict; use 5.014; use Net::SMTP; use config2; my $link = shift; my $sub_hash = "my_ftp"; my $host = $config{$sub_hash}->{'site'}; say "host is $host"; my $phone = $config{$sub_hash}->{'phone'}; say "phone is $phone"; if (exists $ENV{USER} && $ENV{USER}) { use Net::SMTP::TLS; my $mailer = new Net::SMTP::TLS( $host, #Hello => 'some.host.name', Port => 25, #redundant User => 'emailguy', Password=> 's3cr3t') or die "Unable to connect to '$host'. $@"; $mailer->mail($ENV{USER}); $mailer->to($phone); $mailer->data; $mailer->datasend($link); $mailer->dataend; $mailer->quit; } else { say '$ENV{USER} does not exists or is not defined.'; } } __END__

      Thank you for your continued attention. I can type again and give better reports of what is or is not happening. I think my values of lexical variables going into it are correct. Again, I use ellipses for values I'd rather not splash all over the net. Output:

      page is 7ae191.html host is smtp.1and1.com phone is ...@txt.att.net username is ... password is ... ******************************************************************* Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER together with SSL_ca_file|SSL_ca_path for verification. If you really don't want to verify the certificate and keep the connection open to Man-In-The-Middle attacks please set SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application. ******************************************************************* at C:/Perl/site/lib/Net/SMTP/TLS.pm line 181. invalid SSL_version specified at C:/Perl/lib/IO/Socket/SSL.pm line 389 +.

      Current script

      #!/usr/bin/perl -w use strict; use 5.010; use lib "template_stuff"; use html3; sub rndStr{ join'', @_[ map{ rand @_ } 1 .. shift ] } my $new_name = rndStr( 5, 'a'..'z', 1..9); my $ref_to_name = \$new_name; my $return_page = create_page($ref_to_name); say "page is $return_page"; email_link($return_page); sub email_link{ use strict; use 5.014; use Net::SMTP; use config2; my $link = shift; my $sub_hash = "my_ftp"; my $host = $config{$sub_hash}->{'smtp'}; say "host is $host"; my $phone = $config{$sub_hash}->{'phone'}; say "phone is $phone"; my $username = $config{$sub_hash}->{'username'}; say "username is $username"; my $password = $config{$sub_hash}->{'password'}; say "password is $password"; if (1) { use Net::SMTP::TLS; my $mailer = new Net::SMTP::TLS( $host, #Hello => 'some.host.name', Port => 587, #redundant User => $username, Password=> $password) or die "Unable to connect to '$host'. $@"; $mailer->mail("myself"); $mailer->to($phone); $mailer->data; $mailer->datasend($link); $mailer->dataend; $mailer->quit; } else { say '$ENV{USER} does not exists or is not defined.'; } } __END__

      So again, I'm wondering how I seem to be making hard what everyone else thinks is super easy....