Probleme mit sendemail sendSnapshot in 99_myUtils

Begonnen von webdandy, 09 Februar 2022, 20:14:02

Vorheriges Thema - Nächstes Thema

webdandy

Hallo zusammen,

ich komme leider nicht weiter und hoffe, dass mir hier jemand helfen kann  :D
Nach der Mail Umstellung von gmail zu zoho muss der Server 127.0.0.0:11125 sein. Doch obwohl ich den Port angebe, versucht sendemail aus FHEM immer nur 127.0.0.1 anzusprechen und schlägt fehl. Ich erhalte den folgenden Fehler:

Feb  9 19:59:44 SmartHome-Pi4 postfix/smtpd[1693]: connect from localhost[127.0.0.1]
Feb  9 19:59:44 SmartHome-Pi4 postfix/smtpd[1693]: SSL_accept error from localhost[127.0.0.1]: -1
Feb  9 19:59:44 SmartHome-Pi4 postfix/smtpd[1693]: warning: TLS library problem: error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca:../ssl/record/rec_layer_s3.c:1544:SSL alert number 48:
Feb  9 19:59:44 SmartHome-Pi4 postfix/smtpd[1693]: lost connection after STARTTLS from localhost[127.0.0.1]
Feb  9 19:59:44 SmartHome-Pi4 postfix/smtpd[1693]: disconnect from localhost[127.0.0.1] ehlo=1 starttls=0/1 commands=1/2


sendSnapshot(@)
{
  my ($cam,$snapshots) = @_;
  my $storage = AttrVal($cam,"storage","");
  my $rcpt = 'xxx@xxxx.com';
  my $from = 'xxx@xxx.com';
  my $subj = "FHEM: Kamera $cam hat eine Bewegung aufgezeichnet";
  my $last = ReadingsTimestamp($cam,"last","");
  my $mess = "Kamera $cam hat eine Bewegung am $last aufgezeichnet:";
  my $user = 'xxx@xxx.com';
  my $passwd = 'xxx';
  my $server = '127.0.0.1:11125';
  if(!-d $storage) {
    Log 1, "IPCAM $cam storagepath does not exists: $storage";
    return "storagepath for $cam does not exists: $storage";
  }
  if(!$last) {
    Log 1, "IPCAM $cam no snapshots available";
    return "no snapshots available for $cam";
  }
  my $cmd  = "sendemail -f $from -t $rcpt -u $subj -m $mess ";
     $cmd .= "-o message-content-type=text -o message-charset=utf-8 -s '$server' -xu '$user' -xp '$passwd' -o tls=auto -a";
  for (my $s=1;$s<$snapshots+1;$s++) {
    $cmd .= " $storage/".ReadingsVal($cam,"snapshot$s","");
  }
  my $ret  = `$cmd`;
  $ret =~ s/[\r\n]//g;
  Log 4, "IPCAM sendSnapshot: $ret";
  return undef;
}



Teste ich sendemail auf der cli klappt es wie folgt:
sendEmail -vv -f 'xxx@xxx.com' -t 'xxx@xxx.com' -u 'subject' -m 'body' -s '127.0.0.1' -xu 'xxx@xxx.com' -xp 'xxx' -o tls=auto


Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => Connecting to 127.0.0.1:11125
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => My IP address is: 127.0.0.1
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 220
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 220 mx.zoho.eu SMTP Server ready February 9, 2022 8:10:59 PM CET
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending: EHLO smarthome-pi4.webdandy.local
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 250-mx.zoho.eu Hello smarthome-pi4.webdandy.local (i5E863906.versanet.de (94.134.57.6)), 250-AUTH LOGIN PLAIN, 250 SIZE 53477376
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => The remote SMTP server does NOT support TLS :(
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => SMTP-AUTH: Using LOGIN authentication method
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending: AUTH LOGIN
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 334
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 334 VXNlcm5hbWU6
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending: d2ViZGFuZHlAd2ViZGFuZHkuY29t
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 334
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 334 UGFzc3dvcmQ6
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending: SzR6eVU1VVZCMVdh
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 235
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 235 Authentication Successful
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => User authentication was successful (Method: LOGIN)
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending: MAIL FROM:<x@x.com>
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 250 Sender <x@x.com> OK
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending: RCPT TO:<x@x.com>
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 250 Recipient <x@x.com> OK
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending: DATA
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 354
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 354 Ok Send data ending with <CRLF>.<CRLF>
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: INFO => Sending message body
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: Setting content-type: text/plain
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: SUCCESS => Received: 250 Message received
Feb 09 20:10:59 smarthome-pi4 sendEmail[2146]: Email was sent successfully!  From: <x@x.com> To: <x@x.com> Subject: [subject] Server: [127.0.0.1:11125]


Schon mal vielen Dank & Gruß
Fabian

Otto123

Hallo Fabian,

was mir auffällt:
SmartHome-Pi4 postfix/smtpd[1693]      versus                  smarthome-pi4 sendEmail[2146]
und
my $cmd  = "sendemail -f $from             versus                 sendEmail -vv -f 'xxx@xxx.com'

Du probierst es mal mit Äpfeln mal mit Birnen?

Also je nach Systemversion war es mal egal / mal nicht egal ob man sendemail oder sendEmail schreibt. Scheinbar hast Du zwei unterschiedliche Programme installiert?

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

webdandy

Hallo Otto,

stimmt, das habe ich gar nicht gesehen. Aber das war es leider nicht  :(

Das Problem ist, dass der Befehl in der 99_myUtils localhost mit Port 25 anspricht und dann den postfix kontaktiert.
Angesprochen werden muss aber stunnel auf localhost mit Port 11125, damit dieser eine 465 Verbindung zu smtp.zoho.eu aufbauen kann.
Systemweit funktioniert der Mailversand.

Grüße
Fabian

root@SmartHome-Pi4 /opt/fhem/FHEM # sendemail --help

sendemail-1.56 by Brandon Zehm <caspian@dotconf.net>

Synopsis:  sendemail -f ADDRESS [options]

  Required:
    -f ADDRESS                from (sender) email address
    * At least one recipient required via -t, -cc, or -bcc
    * Message body required via -m, STDIN, or -o message-file=FILE

  Common:
    -t ADDRESS [ADDR ...]     to email address(es)
    -u SUBJECT                message subject
    -m MESSAGE                message body
    -s SERVER[:PORT]          smtp mail relay, default is localhost:25
    -S [SENDMAIL_PATH]        use local sendmail utility (default: /usr/bin/sendmail) instead of network MTA

  Optional:
    -a   FILE [FILE ...]      file attachment(s)
    -cc  ADDRESS [ADDR ...]   cc  email address(es)
    -bcc ADDRESS [ADDR ...]   bcc email address(es)
    -xu  USERNAME             username for SMTP authentication
    -xp  PASSWORD             password for SMTP authentication

  Paranormal:
    -b BINDADDR[:PORT]        local host bind address
    -l LOGFILE                log to the specified file
    -v                        verbosity, use multiple times for greater effect
    -q                        be quiet (i.e. no STDOUT output)
    -o NAME=VALUE             advanced options, for details try: --help misc
        -o message-content-type=<auto|text|html>
        -o message-file=FILE         -o message-format=raw
        -o message-header=HEADER     -o message-charset=CHARSET
        -o reply-to=ADDRESS          -o timeout=SECONDS
        -o username=USERNAME         -o password=PASSWORD
        -o tls=<auto|yes|no>         -o fqdn=FQDN


  Help:
    --help                    the helpful overview you're reading now
    --help addressing         explain addressing and related options
    --help message            explain message body input and related options
    --help networking         explain -s, -b, etc
    --help output             explain logging and other output options
    --help misc               explain -o options, TLS, SMTP auth, and more

root@SmartHome-Pi4 /opt/fhem/FHEM # sendEmail --help

sendEmail-1.56 by Brandon Zehm <caspian@dotconf.net>

Synopsis:  sendEmail -f ADDRESS [options]

  Required:
    -f ADDRESS                from (sender) email address
    * At least one recipient required via -t, -cc, or -bcc
    * Message body required via -m, STDIN, or -o message-file=FILE

  Common:
    -t ADDRESS [ADDR ...]     to email address(es)
    -u SUBJECT                message subject
    -m MESSAGE                message body
    -s SERVER[:PORT]          smtp mail relay, default is localhost:25
    -S [SENDMAIL_PATH]        use local sendmail utility (default: /usr/bin/sendmail) instead of network MTA

  Optional:
    -a   FILE [FILE ...]      file attachment(s)
    -cc  ADDRESS [ADDR ...]   cc  email address(es)
    -bcc ADDRESS [ADDR ...]   bcc email address(es)
    -xu  USERNAME             username for SMTP authentication
    -xp  PASSWORD             password for SMTP authentication

  Paranormal:
    -b BINDADDR[:PORT]        local host bind address
    -l LOGFILE                log to the specified file
    -v                        verbosity, use multiple times for greater effect
    -q                        be quiet (i.e. no STDOUT output)
    -o NAME=VALUE             advanced options, for details try: --help misc
        -o message-content-type=<auto|text|html>
        -o message-file=FILE         -o message-format=raw
        -o message-header=HEADER     -o message-charset=CHARSET
        -o reply-to=ADDRESS          -o timeout=SECONDS
        -o username=USERNAME         -o password=PASSWORD
        -o tls=<auto|yes|no>         -o fqdn=FQDN


  Help:
    --help                    the helpful overview you're reading now
    --help addressing         explain addressing and related options
    --help message            explain message body input and related options
    --help networking         explain -s, -b, etc
    --help output             explain logging and other output options
    --help misc               explain -o options, TLS, SMTP auth, and more

Otto123

#3
Also kann ja sein, das sendemail einen bug bei localhost hat, aber was Du bisher an echten Ausschriften gepostet hast passt für mich nicht zusammmen.
Dein Test enthält keinen Port aber es klappt? ::)
ZitatTeste ich sendemail auf der cli klappt es wie folgt:
Code: [Auswählen]
sendEmail -vv -f 'xxx@xxx.com' -t 'xxx@xxx.com' -u 'subject' -m 'body' -s '127.0.0.1' -xu 'xxx@xxx.com' -xp 'xxx' -o tls=auto

In deiner Utils entdecke ich erstmal keinen Fehler. Bau doch vor dem Ende ein return $cmd ein, teste die Sub in der FHEM Kommandozeile, schau Dir den Befehl an und teste genau diesen. Vielleicht ist doch an anderer Stelle ein bug. 

Bist Du sicher, dass sendEmail und sendemail bei Dir das gleiche ist?
pi@raspib3:~ $ which sendemail
/usr/bin/sendemail
pi@raspib3:~ $ which sendEmail
/usr/bin/sendEmail
pi@raspib3:~ $
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

webdandy

Sorry, ich habe natürlich blödsinn gepostet  ???
Der erfolgreiche Test per CLI klappt natürlich nur so:

sendEmail -vv -f 'xxx@xxx.com' -t 'xxx@xxx.com' -u 'subject' -m 'body' -s '127.0.0.1:11125' -xu 'xxx@xxx.com' -xp 'xxx' -o tls=auto

ZitatIn deiner Utils entdecke ich erstmal keinen Fehler. Bau doch vor dem Ende ein return $cmd ein, teste die Sub in der FHEM Kommandozeile, schau Dir den Befehl an und teste genau diesen. Vielleicht ist doch an anderer Stelle ein bug.

Wie genau meinst du das? Sorry für die Frage  ;)

Grüße
Fabian

Otto123

Irgendwas muss ja an dem Ergebnis Deiner sub anders sein als Dein Test in der Kommandozeile ...
sendSnapshot(@)
{
  my ($cam,$snapshots) = @_;
  my $storage = AttrVal($cam,"storage","");
  my $rcpt = 'xxx@xxxx.com';
  my $from = 'xxx@xxx.com';
  my $subj = "FHEM: Kamera $cam hat eine Bewegung aufgezeichnet";
  my $last = ReadingsTimestamp($cam,"last","");
  my $mess = "Kamera $cam hat eine Bewegung am $last aufgezeichnet:";
  my $user = 'xxx@xxx.com';
  my $passwd = 'xxx';
  my $server = '127.0.0.1:11125';
  if(!-d $storage) {
    Log 1, "IPCAM $cam storagepath does not exists: $storage";
    return "storagepath for $cam does not exists: $storage";
  }
  if(!$last) {
    Log 1, "IPCAM $cam no snapshots available";
    return "no snapshots available for $cam";
  }
  my $cmd  = "sendemail -f $from -t $rcpt -u $subj -m $mess ";
     $cmd .= "-o message-content-type=text -o message-charset=utf-8 -s '$server' -xu '$user' -xp '$passwd' -o tls=auto -a";
  for (my $s=1;$s<$snapshots+1;$s++) {
    $cmd .= " $storage/".ReadingsVal($cam,"snapshot$s","");
  }
  ## nur zum test, Aufruf einfach in der FHEM Kommandozeile {sendSnapshot ('cam', 'snapshot')}
  return $cmd;
  #################
  my $ret  = `$cmd`;
  $ret =~ s/[\r\n]//g;
  Log 4, "IPCAM sendSnapshot: $ret";
  return undef;
}
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

webdandy

Wenn ich {sendSnapshot ('cam', 'snapshot')} eingebe, kommt Undefined subroutine &main::sendSnapshot called at (eval 85719) line 1.

Otto123

Dann hast Du hast Du keine sub sendSnapshot in deiner 99_myUtils  ::) oder deine 99_myUtils ist nicht geladen
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

webdandy

#8
Hallo Otto,
er war ein Anfängerfehler  ;D
Mir war nicht bewusst, dass man bei jeder Änderung in der 99_myUtils FHEM neustarten muss, damit diese neu geladen wird.
Jedenfalls war dies bei mir wohl das Problem. Mit der folgenden Konfiguration klappt es jetzt  :D

sub
sendSnapshot(@)
{
  my ($cam,$snapshots) = @_;
  my $storage = AttrVal($cam,"storage","");
  my $rcpt = 'x@x.com';
  my $from = 'x@x.com';
  my $subj = "FHEM: Kamera $cam hat eine Bewegung aufgezeichnet";
  my $last = ReadingsTimestamp($cam,"last","");
  my $mess = "Kamera $cam hat eine Bewegung am $last aufgezeichnet:";
  my $server = '127.0.0.1:11125';
  my $user = 'x@x.com';
  my $passwd = 'x';
  if(!-d $storage) {
    Log 1, "IPCAM $cam storagepath does not exists: $storage";
    return "storagepath for $cam does not exists: $storage";
  }
  if(!$last) {
    Log 1, "IPCAM $cam no snapshots available";
    return "no snapshots available for $cam";
  }
  my $cmd  = "sendemail -f $from -t $rcpt -u $subj -m $mess ";
     $cmd .= "-o message-content-type=text -o message-charset=utf-8 -s $server -xu $user -xp $passwd -o tls=auto -a";
  for (my $s=1;$s<$snapshots+1;$s++) {
    $cmd .= " $storage/".ReadingsVal($cam,"snapshot$s","");
  }
  my $ret  = `$cmd`;
  $ret =~ s/[\r\n]//g;
  Log 4, "IPCAM sendSnapshot: $ret";
  return undef;
}


Vielen Dank für die schnelle Unterstützung hier im Forum mal wieder.

Grüße
Fabian

Otto123

Zitat von: webdandy am 09 März 2022, 09:23:19
Mir war nicht bewusst, dass man bei jeder Änderung in der 99_myUtils FHEM neustarten muss, damit diese neu geladen wird.
Hallo Fabian,

wenn die 99_myUtils über den in FHEM integrierten Editor bearbeitet wird, wird sie nach dem speichern automatisch neu geladen.

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

webdandy

Dann sollte ich wohl lieber den Editor benutzen, als auf der Konsole mit vi in den Dateien  ;D


webdandy

Mist, hatte extra alles raus gex in einer datei und dann doch das falsche gepostet. danke für den hinweis!
gelöscht und neues passwort vergeben.. danke