http://qs321.pair.com?node_id=11102083

*alexandre* has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to send email from my web application but I got a connexion refused. I've installed hMailServer, and writte the Following code
#!"C:\xampp\perl\bin\perl.exe" use strict; use warnings; use MIME::Lite; my $Message = new MIME::Lite From =>'robot@localhost.localdomain', To =>'robot@localhost.localdomain', Subject =>'test' +, Type =>'TEXT', Data =>'test register'; $Message->attr("content-type" => "text/html; charset=iso-8859-1"); $Message->send_by_smtp('localhost:25'); print "Content-Type: text/html\n\n"; print "Send email from windows 10 ok";
the Following code found a fatal error at this line
$Message->send_by_smtp('localhost:25');

Replies are listed 'Best First'.
Re: sending email under windows 10
by holli (Abbot) on Jun 28, 2019 at 14:58 UTC
    If the mailserver is configured properly it will refuse the connection because it cannot authenticate you. SMTP itself has no auth mechanism so the way it normally works is that you have to do a fetch first, via POP3 which does support auth. At least that's how Gmail and web.de do it. I just learned there is also SMTP-Auth now. So in essence, check your mailservers config and see how it handles auth.


    holli

    You can lead your users to water, but alas, you cannot drown them.
Re: sending email under windows 10
by poj (Abbot) on Jun 28, 2019 at 15:03 UTC
      I'm been trying to send mail through telnet within the Following
      $ telnet localhost 587 Trying ::1... Connection failed: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 localhost ESMTP OK 503 Bad sequence of commands ehlo localhost 250-localhost 250-SIZE 20480000 250-AUTH LOGIN 250 HELP mail from:robot@avant-garde.no-ip.biz 250 OK data 503 Must have sender and recipient first. rcpt to:alexjaquet@gmail.com 530 SMTP authentication is required.

        Your program used port 25 but now you're telnetting port 587... could that be the problem?

        Edit (in response below):

        $Message->send_by_smtp('localhost:587'); #-- assuming program runs o +n same host as mailserver # (otherwise also adapt ' +localhost' or try to # set it to '127.0.0.1' +in case of IP6 confusion)
Re: sending email under windows 10
by soonix (Canon) on Jun 28, 2019 at 14:41 UTC
    Any hint of an error message, e.g. "connection refused" or somesuch?
      I also tryed to send email like this way
      #!"C:\xampp\perl\bin\perl.exe" $to = 'alexjaquet@gmail.com'; $from = 'robot@company.com'; $subject = 'Party!!!'; $message = 'Details of party'; open(MAIL, "c:/xampp/sendmail/sendmail.exe -t"); # Email Header print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; # Email Body print MAIL $message; close(MAIL); print "Content-Type: text/html\n\n"; print "Email Sent Successfully\n"; print "Send email from windows 10 ok";
      it print the message without any errors but no mail is sended I'm still investigating solutions to fix my problem, here is a new script I found
      #!"C:\xampp\perl\bin\perl.exe" use strict; use warnings; use Email::Sender::Simple qw(sendmail); use Email::Sender::Transport::SMTPS (); use Email::Simple (); use Email::Simple::Creator (); my $smtpserver = 'localhost'; my $smtpport = 587; my $smtpuser = 'robot@localhost.localdomain'; my $smtppassword = 'test'; my $transport = Email::Sender::Transport::SMTPS->new({ host => $smtpserver, port => $smtpport, ssl => "starttls", sasl_username => $smtpuser, sasl_password => $smtppassword, }); my $email = Email::Simple->create( header => [ To => 'alexjaquet@gmail.com', From => 'robot@avant-garde.no-ip.biz', Subject => 'Hi!', ], body => "This is my message\n", ); sendmail($email, { transport => $transport });
      this script give me the Following error
      [Sun Jun 30 15:15:31.745191 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] End of script output before headers: mail4.pl [Sun Jun 30 15:15:31.745191 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: unable to establish SMTP connection\r: C:/xam +pp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.745191 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: \r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.745191 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Trace begun at C:\\xampp\\perl\\site\\lib\\Em +ail\\Sender\\Transport\\SMTPS.pm line 98\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.745707 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Transport::SMTPS::_throw('Emai +l::Sender::Transport::SMTPS=HASH(0x3b72f08)', 'unable to establish SM +TP connection') called at C:\\xampp\\perl\\site\\lib\\Email\\Sender\\ +Transport\\SMTPS.pm line 60\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.746205 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Transport::SMTPS::_smtp_client +('Email::Sender::Transport::SMTPS=HASH(0x3b72f08)') called at C:\\xam +pp\\perl\\site\\lib\\Email\\Sender\\Transport\\SMTPS.pm line 107\r: C +:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.746726 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Transport::SMTPS::send_email(' +Email::Sender::Transport::SMTPS=HASH(0x3b72f08)', 'Email::Abstract=AR +RAY(0x1189a18)', 'HASH(0x27d4440)') called at C:\\xampp\\perl\\vendor +\\lib\\Email\\Sender\\Role\\CommonSending.pm line 45\r: C:/xampp/cgi- +bin/mail4.pl [Sun Jun 30 15:15:31.746726 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Role::CommonSending::try {...} + at C:\\xampp\\perl\\vendor\\lib\\Try\\Tiny.pm line 102\r: C:/xampp/ +cgi-bin/mail4.pl [Sun Jun 30 15:15:31.746726 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: eval {...} at C:\\xampp\\perl\\vendor\\lib\\T +ry\\Tiny.pm line 93\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.747195 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Try::Tiny::try('CODE(0x446b5a8)', 'Try::Tiny: +:Catch=REF(0x3b72a58)') called at C:\\xampp\\perl\\vendor\\lib\\Email +\\Sender\\Role\\CommonSending.pm line 58\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.747195 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Role::CommonSending::send('Ema +il::Sender::Transport::SMTPS=HASH(0x3b72f08)', 'Email::Abstract=ARRAY +(0x1189a18)', 'HASH(0x44659c8)') called at C:\\xampp\\perl\\vendor\\l +ib\\Email\\Sender\\Simple.pm line 119\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.747691 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Simple::send_email('Email::Sen +der::Simple', 'Email::Abstract=ARRAY(0x1189a18)', 'HASH(0x3b697c8)') +called at C:\\xampp\\perl\\vendor\\lib\\Email\\Sender\\Role\\CommonSe +nding.pm line 45\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.747691 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Role::CommonSending::try {...} + at C:\\xampp\\perl\\vendor\\lib\\Try\\Tiny.pm line 102\r: C:/xampp/ +cgi-bin/mail4.pl [Sun Jun 30 15:15:31.747691 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: eval {...} at C:\\xampp\\perl\\vendor\\lib\\T +ry\\Tiny.pm line 93\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.748205 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Try::Tiny::try('CODE(0x27d4788)', 'Try::Tiny: +:Catch=REF(0x3b57420)') called at C:\\xampp\\perl\\vendor\\lib\\Email +\\Sender\\Role\\CommonSending.pm line 58\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.748683 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Email::Sender::Role::CommonSending::send('Ema +il::Sender::Simple', 'Email::Simple=HASH(0x27d46c8)', 'HASH(0x27d4200 +)') called at C:\\xampp\\perl\\vendor\\lib\\Sub\\Exporter\\Util.pm li +ne 18\r: C:/xampp/cgi-bin/mail4.pl [Sun Jun 30 15:15:31.748683 2019] [cgi:error] [pid 6624:tid 1868] [cli +ent ::1:64916] AH01215: Sub::Exporter::Util::__ANON__('Email::Simple= +HASH(0x27d46c8)', 'HASH(0x27d4200)') called at C:\\xampp\\cgi-bin\\ma +il4.pl line 32\r: C:/xampp/cgi-bin/mail4.pl
      My hMailServer hostname is localhost and run within the port 587
        This code work's well within an gmail account who have the AppPassword created ;-)