Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Net::SMTP - Connection to local MTA refused

by noxxi (Pilgrim)
on Mar 07, 2017 at 05:22 UTC ( [id://1183813]=note: print w/replies, xml ) Need Help??


in reply to Net::SMTP - Connection to local MTA refused

It is unknown what kind of setup you really have but "Connection refused" is usually caused either by a firewall blocking connections (unlikely with localhost) or that simply no server is listening there.
Based on your use of Net::SMTP connection should work if you have a MTA setup on localhost port 465 (smtps), speaking directly TLS (i.e. no upgrade with STARTTLS) and with a valid certificate for "localhost". I have no idea if this is really the case but I would guess it is not.
To better debug the problem I would recommend to use the "Debug" switch for Net::SMTP. For SSL debugging run your code with "perl -MIO::Socket::SSL=debug4 program.pl".

Replies are listed 'Best First'.
Re^2: Net::SMTP - Connection to local MTA refused
by Robidu (Acolyte) on Mar 07, 2017 at 08:41 UTC

    The point is that the connection attempt does show up in the logs, but beyond the connection being initiated, nothing more happens. I'm experiencing the same issues when I set SSL => 0 (this is still possible, because my MTA is configured so that TLS doesn't have to be used for incoming mails) so it's not a problem with SSL/TLS, though. As far as the form mailer is concerned, it is supposed to transmit its data on port 25. No idea why it stopped working after upgrading the distro...

    However, I'm going to give the Debug approach a shot.

    EDIT: It appears that STARTTLS is required, but the method starttls() seems to be missing in my Net::SMTP...

    Anyway, here's what the script dumped with Debug enabled:

    Sanity check of recipient address... <recipient address displayed here> Net::SMTP>>> Net::SMTP(2.31) Net::SMTP>>> Net::Cmd(2.29) Net::SMTP>>> Exporter(5.68) Net::SMTP>>> IO::Socket::INET(1.33) Net::SMTP>>> IO::Socket(1.36) Net::SMTP>>> IO::Handle(1.34) Net::SMTP=GLOB(0x1c9d748)<<< 220 <domain name displayed here> mail. Al +l spam is reported. ESMTP Net::SMTP=GLOB(0x1c9d748)>>> EHLO <domain displayed here> Net::SMTP=GLOB(0x1c9d748)<<< 250-<server name displayed here> Net::SMTP=GLOB(0x1c9d748)<<< 250-PIPELINING Net::SMTP=GLOB(0x1c9d748)<<< 250-SIZE 26214400 Net::SMTP=GLOB(0x1c9d748)<<< 250-ETRN Net::SMTP=GLOB(0x1c9d748)<<< 250-STARTTLS Net::SMTP=GLOB(0x1c9d748)<<< 250-ENHANCEDSTATUSCODES Net::SMTP=GLOB(0x1c9d748)<<< 250-8BITMIME Net::SMTP=GLOB(0x1c9d748)<<< 250 DSN Issuing STARTTLS... Net::SMTP=GLOB(0x1c9d748)>>> QUIT Net::SMTP=GLOB(0x1c9d748)<<< 221 2.0.0 Bye The transaction failed: Can't locate object method "starttls" via pack +age "Net::SMTP" at /srv/www1-ssl/cgi-lib/sendmail.pm line 74. Transmission failure

    UPDATE: I had to update both Net::SMTP and IO::Socket::SSL from CPAN. After the update STARTTLS could be issued, but that caused another bunch of problems to appear:

    Sanity check of recipient address... <recipient address shown here> Net::SMTP>>> Net::SMTP(3.10) Net::SMTP>>> Net::Cmd(3.10) Net::SMTP>>> Exporter(5.68) Net::SMTP>>> IO::Socket::IP(0.37) Net::SMTP>>> IO::Socket(1.36) Net::SMTP>>> IO::Handle(1.34) Net::SMTP=GLOB(0x20461c8)<<< 220 <domain shown here> mail. All spam is + reported. ESMTP Net::SMTP=GLOB(0x20461c8)>>> EHLO <domain shown here> Net::SMTP=GLOB(0x20461c8)<<< 250-<server address shown here> Net::SMTP=GLOB(0x20461c8)<<< 250-PIPELINING Net::SMTP=GLOB(0x20461c8)<<< 250-SIZE 26214400 Net::SMTP=GLOB(0x20461c8)<<< 250-ETRN Net::SMTP=GLOB(0x20461c8)<<< 250-STARTTLS Net::SMTP=GLOB(0x20461c8)<<< 250-ENHANCEDSTATUSCODES Net::SMTP=GLOB(0x20461c8)<<< 250-8BITMIME Net::SMTP=GLOB(0x20461c8)<<< 250 DSN Issuing STARTTLS... Net::SMTP=GLOB(0x20461c8)>>> STARTTLS Net::SMTP=GLOB(0x20461c8)<<< 220 2.0.0 Ready to start TLS Sending MAIL FROM... Net::SMTP=GLOB(0x20461c8)>>> MAIL FROM:<sender address shown here> Net::SMTP: Net::Cmd::getline(): unexpected EOF on command channel: at + /srv/www1-ssl/cgi-lib/sendmail.pm line 76. Attempting RCPT TO... Net::SMTP: Net::Cmd::_is_closed(): unexpected EOF on command channel: + at /srv/www1-ssl/cgi-lib/sendmail.pm line 78. Net::SMTP: Net::Cmd::_is_closed(): unexpected EOF on command channel: + at /srv/www1-ssl/cgi-lib/sendmail.pm line 78. Net::SMTP: Net::Cmd::_is_closed(): unexpected EOF on command channel: + at /srv/www1-ssl/cgi-lib/sendmail.pm line 102. Net::SMTP: Net::Cmd::_is_closed(): unexpected EOF on command channel: + at /srv/www1-ssl/cgi-lib/sendmail.pm line 102. The transaction failed: Connection refused Transmission failure
      It appears the MTA is closing the connection right after you send the "MAIL FROM:" string.
      Net::SMTP=GLOB(0x20461c8)>>> MAIL FROM:<sender address shown here>
      Net::SMTP: Net::Cmd::getline(): unexpected EOF on command channel:  at
      + /srv/www1-ssl/cgi-lib/sendmail.pm line 76.
      

      So, it's either the MTA itself, or some external thing like AppArmor (enabled by default in the OpenSuse version you mention).

      I would look at the logs for whatever your MTA is (exim maybe?) as well as AppArmor, SELinux, or whatever other external security stuff you may have running.

      Maybe also try "service boot.apparmor stop", and see if turning off AppArmor makes a difference. Not the right solution, but quick to try.

        My MTA is Postfix, and AppArmor is disabled (I'm currently running SELinux in Permissive mode so that doesn't interfere at the moment).

        Unfortunately the logs haven't turned up anything that could be of help so I'm at a loss here.

      ok, i may be missing something here, but dont modern mail senders require you to authenticate first? ie:

      $l_mailer->auth($smtpuser, $smtppassword);
      before
      $l_mailer->mail($p_sender);

        That would be necessary if the form mailer sent its data through the submission port (587/tcp). However, I'm sending this through port 25 which doesn't require authentication (it's normally used so that other MTAs can connect, but localhost is allowed to send there, too).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1183813]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found