Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Net::SMTPS => auth no longer works - Migration from Debian to Docker container

by initB10r (Initiate)
on Jan 06, 2020 at 08:01 UTC ( [id://11111034]=perlquestion: print w/replies, xml ) Need Help??

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

Hello together,

i have ported my installation from a Debian installation to a docker container.
Here I use a simple Perl module to send emails.
Under docker this no longer works.

I have already tested a lot with the following modules:
use Net::SSL;
use Net::TLS;
use Net::SMTPS;

But with all modules the authentication fails.

The credentials are definitely correct, because on the Debian installation everything works without problems.

Here is my code:
#!/usr/bin/perl use strict; use warnings; use Net::SMTPS; use Authen::SASL; my $user = 'postausgangFHEM@domain.de'; my $pass = 'KnAM'; my $sender = 'fhem@domain.de'; my $rcpt = 'marc@domain.de'; my $server = 'smtp.strato.de'; my $domain = 'www.strato.de'; my $mail_sasl_type = 'starttls'; my $server_port = 587; my $smtp = Net::SMTPS->new( $server, Port => $server_port, Debug => 1, + doSSL => $mail_sasl_type) || die "cannot connect to server ${server} +"; my $sasl = Authen::SASL->new( mechanism => 'PLAIN', debug => 1, callba +ck => {pass => $pass, user => $user}); $smtp->auth( $sasl ) || die "cannot do mail auth"; $smtp->mail($sender) or die "Error:".$smtp->message(); $smtp->to($rcpt) or die "Error:".$smtp->message(); $smtp->data() or die "Error:".$smtp->message(); $smtp->datasend("Subject: Mein Subject\n"); $smtp->datasend("\n"); $smtp->datasend("Mein Body"); $smtp->dataend() or die "Error:".$smtp->message(); $smtp->quit() or die "Error:".$smtp->message();

And here is the result:
root@schneckenFhem:/opt/fhem# perl ./FHEM/sendEmail.pm Net::SMTPS>>> Net::SMTPS(0.09) Net::SMTPS>>> IO::Socket::IP(0.39) Net::SMTPS>>> IO::Socket(1.39) Net::SMTPS>>> IO::Handle(1.39) Net::SMTPS>>> Exporter(5.73) Net::SMTPS>>> Net::SMTP(3.11) Net::SMTPS>>> Net::Cmd(3.11) Net::SMTPS=GLOB(0x562fb253e128)<<< 220 smtp.strato.de ESMTP RZmta (P12 + -) Net::SMTPS=GLOB(0x562fb253e128)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x562fb253e128)<<< 250-smtp.strato.de greets 89.244.23 +0.217 Net::SMTPS=GLOB(0x562fb253e128)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x562fb253e128)<<< 250-PIPELINING Net::SMTPS=GLOB(0x562fb253e128)<<< 250-8BITMIME Net::SMTPS=GLOB(0x562fb253e128)<<< 250-DELIVERBY Net::SMTPS=GLOB(0x562fb253e128)<<< 250-SIZE 104857600 Net::SMTPS=GLOB(0x562fb253e128)<<< 250-AUTH PLAIN LOGIN CRAM-MD5 DIGES +T-MD5 Net::SMTPS=GLOB(0x562fb253e128)<<< 250-STARTTLS Net::SMTPS=GLOB(0x562fb253e128)<<< 250-BURL imap Net::SMTPS=GLOB(0x562fb253e128)<<< 250-CHUNKING Net::SMTPS=GLOB(0x562fb253e128)<<< 250 HELP Net::SMTPS=GLOB(0x562fb253e128)>>> STARTTLS Net::SMTPS=GLOB(0x562fb253e128)<<< 220 Ready to start TLS Net::SMTPS=GLOB(0x562fb253e128)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x562fb253e128)<<< 250-smtp.strato.de greets 89.244.23 +0.217 Net::SMTPS=GLOB(0x562fb253e128)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x562fb253e128)<<< 250-PIPELINING Net::SMTPS=GLOB(0x562fb253e128)<<< 250-8BITMIME Net::SMTPS=GLOB(0x562fb253e128)<<< 250-DELIVERBY Net::SMTPS=GLOB(0x562fb253e128)<<< 250-SIZE 104857600 Net::SMTPS=GLOB(0x562fb253e128)<<< 250-AUTH PLAIN LOGIN CRAM-MD5 DIGES +T-MD5 Net::SMTPS=GLOB(0x562fb253e128)<<< 250-REQUIRETLS Net::SMTPS=GLOB(0x562fb253e128)<<< 250-BURL imap Net::SMTPS=GLOB(0x562fb253e128)<<< 250-CHUNKING Net::SMTPS=GLOB(0x562fb253e128)<<< 250 HELP cannot do mail auth at ./FHEM/sendEmail.pm line 20.
Does anyone have any idea what I can check?

Regards
Marc

Replies are listed 'Best First'.
Re: Net::SMTPS => auth no longer works - Migration from Debian to Docker container
by Lotus1 (Vicar) on Jan 06, 2020 at 18:03 UTC

    From the OP:

    my $smtp = Net::SMTPS->new( $server, Port => $server_port, Debug => 1, + doSSL => +$mail_sasl_type) || die "cannot connect to server ${server}"; my $sasl = Authen::SASL->new( mechanism => 'PLAIN', debug => 1, callba +ck => {pas +s => $pass, user => $user}); $smtp->auth( $sasl ) || die "cannot do mail auth";

    From the output you posted I see the die statement is where it fails at $smtp->auth( $sasl ) || die [...]. Looking at the auth() method I found the documentation points out a difference in Net::SMTPS and Net::SMTP. You might try to specify the AUTHMETHOD as shown at Net::SMTPS.

    METHODS Most of all methods of Net::SMTP are inherited as is, except auth(). auth ( USERNAME, PASSWORD [, AUTHMETHOD]) Attempt SASL authentication through Authen::SASL module. AUTHMETHOD is + your required method of authentication, like 'CRAM-MD5', 'LOGIN', .. +. etc. If your selection does not match the server-offerred AUTH mech +anism, authentication negotiation may fail.

    Also, the synopsis for Authen::SASL shows mechanism specified as a list of the choices. You only provide PLAIN but it might be looking for one of the other options shown in your debug output.

    SYNOPSIS use Authen::SASL; $sasl = Authen::SASL->new( mechanism => 'CRAM-MD5 PLAIN ANONYMOUS', callback => { pass => \&fetch_password, user => $user, } );

    Debug output from Net::SMTPS :

    Net::SMTPS=GLOB(0x562fb253e128)<<< 250-AUTH PLAIN LOGIN CRAM-MD5 DIGES +T-MD5
      That might be some part of it but I doubt it. I suspect that it probably has to do with a network port that isn't exposed to the real world and/or that is being firewalled by Docker. The OP should please post the Dockerfile and docker-compose.yaml content.

        I can't disagree with that. But in looking at the source to the auth() methods I saw a lot of debug prints that weren't in the OP. It seemed like a quick and easy thing to try.

        In the debug output, it shows communications with the server, and SMTP only uses one socket connection, so I dont think that”s it.

        But, having it work outside docker but not inside seems to be the biggest hint. Maybe there are perl modules needed for the auth that didn’t get included in the docker image? Could also be missing SSL certificates or something. A quick way to check would be to run it under strace and see if it tries to open a file right before saying it cant authenticate. (but running strace inside docker requires the --priveleged flag)

        Hello, here is my docker-compose.yml:
        version: '2' services: fhem: restart: always ports: - "8083:8083" - "7072:7072" image: fhem/fhem:latest volumes: - /share/CE_CACHEDEV1_DATA/Docker/Fhem/volumes/core/:/opt/ +fhem/ networks: - fhem-network mac_address: AA:F8:5F:95:84:11 environment: FHEM_UID: 1000 FHEM_GID: 1000 TIMEOUT: 10 RESTART: 1 TELNETPORT: 7072 TZ: Europe/Berlin IMAGE_LAYER_DEV: 1 CPAN_PKGS: "Frontier::Client MIME::Lite" networks: fhem-network: driver: qnet ipam: driver: qnet options: iface: "bond0"
        I also think it has something to do with Docker, since it works in a normal Debian installation.
      Hello I changed the auth methode in 2 ways, but both fails
      first try:
      $smtp->auth( $user, $pass,'PLAIN') || die "cannot do mail auth";
      result
      perl ./FHEM/sendEmail.pm Net::SMTPS>>> Net::SMTPS(0.09) Net::SMTPS>>> IO::Socket::IP(0.39) Net::SMTPS>>> IO::Socket(1.39) Net::SMTPS>>> IO::Handle(1.39) Net::SMTPS>>> Exporter(5.73) Net::SMTPS>>> Net::SMTP(3.11) Net::SMTPS>>> Net::Cmd(3.11) Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 220 smtp.strato.de ESMTP RZmta (P10 + -) Net::SMTPS=GLOB(0x55ffcc1839b0)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-smtp.strato.de greets 89.245.1. +55 Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-PIPELINING Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-8BITMIME Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-DELIVERBY Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-SIZE 104857600 Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-AUTH PLAIN LOGIN CRAM-MD5 DIGES +T-MD5 Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-STARTTLS Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-BURL imap Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-CHUNKING Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250 HELP Net::SMTPS=GLOB(0x55ffcc1839b0)>>> STARTTLS Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 220 Ready to start TLS Net::SMTPS=GLOB(0x55ffcc1839b0)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-smtp.strato.de greets 89.245.1. +55 Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-PIPELINING Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-8BITMIME Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-DELIVERBY Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-SIZE 104857600 Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-AUTH PLAIN LOGIN CRAM-MD5 DIGES +T-MD5 Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-REQUIRETLS Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-BURL imap Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250-CHUNKING Net::SMTPS=GLOB(0x55ffcc1839b0)<<< 250 HELP Net::SMTPS=GLOB(0x55ffcc1839b0)>>> AUTH-my favorite: PLAIN Net::SMTPS=GLOB(0x55ffcc1839b0)>>> AUTH-server offerred: PLAIN LOGIN C +RAM-MD5 DIGEST-MD5 Net::SMTPS=GLOB(0x55ffcc1839b0)>>> AUTH-negotiated: PLAIN cannot do mail auth at ./FHEM/sendEmail.pm line 18.
      2nd try:
      $smtp->auth( $user, $pass,'LOGIN') || die "cannot do mail auth";
      result
      perl ./FHEM/sendEmail.pm Net::SMTPS>>> Net::SMTPS(0.09) Net::SMTPS>>> IO::Socket::IP(0.39) Net::SMTPS>>> IO::Socket(1.39) Net::SMTPS>>> IO::Handle(1.39) Net::SMTPS>>> Exporter(5.73) Net::SMTPS>>> Net::SMTP(3.11) Net::SMTPS>>> Net::Cmd(3.11) Net::SMTPS=GLOB(0x56154bf1cf60)<<< 220 smtp.strato.de ESMTP RZmta (P8 +-) Net::SMTPS=GLOB(0x56154bf1cf60)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-smtp.strato.de greets 89.245.1. +55 Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-PIPELINING Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-8BITMIME Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-DELIVERBY Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-SIZE 104857600 Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-AUTH PLAIN LOGIN CRAM-MD5 DIGES +T-MD5 Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-STARTTLS Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-BURL imap Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-CHUNKING Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250 HELP Net::SMTPS=GLOB(0x56154bf1cf60)>>> STARTTLS Net::SMTPS=GLOB(0x56154bf1cf60)<<< 220 Ready to start TLS Net::SMTPS=GLOB(0x56154bf1cf60)>>> EHLO localhost.localdomain Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-smtp.strato.de greets 89.245.1. +55 Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-ENHANCEDSTATUSCODES Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-PIPELINING Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-8BITMIME Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-DELIVERBY Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-SIZE 104857600 Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-AUTH PLAIN LOGIN CRAM-MD5 DIGES +T-MD5 Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-REQUIRETLS Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-BURL imap Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250-CHUNKING Net::SMTPS=GLOB(0x56154bf1cf60)<<< 250 HELP Net::SMTPS=GLOB(0x56154bf1cf60)>>> AUTH-my favorite: LOGIN Net::SMTPS=GLOB(0x56154bf1cf60)>>> AUTH-server offerred: PLAIN LOGIN C +RAM-MD5 DIGEST-MD5 Net::SMTPS=GLOB(0x56154bf1cf60)>>> AUTH-negotiated: LOGIN cannot do mail auth at ./FHEM/sendEmail.pm line 18.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11111034]
Approved by marto
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found