Hauptmenü

Mail Problem

Begonnen von wthiess, 22 Juni 2016, 11:06:42

Vorheriges Thema - Nächstes Thema

wthiess

Hallo Gemeinde!

Habe auf dem Rasperry wie im wicki http://www.fhemwiki.de/wiki/E-Mail_senden beschrieben die Sendmail funktion installiert.
Ich bekomme folgende Meldung in Fhem.

Undefined subroutine &main::mailsenden called at (eval 67) line 1.

Im 99_Util habe ich folgendes ergänzt. mit meinen Werten natürlich.

Kann mir bitte hier jemand helfen?

lg
Wolfgang


######## DebianMail  Mail auf dem RPi versenden ############
sub
DebianMail
{
my $rcpt = shift;
my $subject = shift;
my $text = shift;
my $attach = shift;
my $ret = "";
my $sender = "absender\@account.de";
my $konto = "kontoname\@account.de";
my $passwrd = "passwrd";
my $provider = "smtp.provider.de:587";
Log 1, "sendEmail RCP: $rcpt";
Log 1, "sendEmail Subject: $subject";
Log 1, "sendEmail Text: $text";
Log 1, "sendEmail Anhang: $attach";;

$ret .= qx(sendEmail -f '$sender' -t '$rcpt' -u '$subject' -m '$text' -a '$attach' -s '$provider' -xu '$konto' -xp '$passwrd' -o tls=auto -o message-charset=utf-8);
$ret =~ s,[\r\n]*,,g;    # remove CR from return-string
Log 1, "sendEmail returned: $ret";
}

Raspberry Pi 3; 8xRelais; Aptodec Nano V3.0 Pro; FS1000a; RF-5V; Hama TS33C; 3x Brennerstuhl FunkSteckdosen; 9x Dooya funk Rollo; KWL Systemair VR400; Thermokon Modbusthermostat; diverse China Modbus Thermostate; 1-wire Bus; Telegram; QuickFhem; FhemNative; Firmata; Alexa ......

Otto123

#1
Zitat von: wthiess am 22 Juni 2016, 11:06:42
Im 99_Util habe ich folgendes ergänzt. mit meinen Werten natürlich.

Das ist nicht der richtige Ort!
99_myUtils
ZitatUndefined subroutine &main::mailsenden called at (eval 67) line 1.
Du bekommst aber eine Fehlermeldung, die darauf deutet, dass Du mailsenden  verwenden willst und es diese Sub gar nicht gibt.

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

wthiess

99_myUtils meinete ich eh Entschuldigung. Schreibfehler. so wie im Wicki beschrieben.

Raspberry Pi 3; 8xRelais; Aptodec Nano V3.0 Pro; FS1000a; RF-5V; Hama TS33C; 3x Brennerstuhl FunkSteckdosen; 9x Dooya funk Rollo; KWL Systemair VR400; Thermokon Modbusthermostat; diverse China Modbus Thermostate; 1-wire Bus; Telegram; QuickFhem; FhemNative; Firmata; Alexa ......

Otto123

Zeige mal zu  Sicherheit Deine komplette 99_myUtils aber bitte in Codetags
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

wthiess

Hier als Anhang oder?
Raspberry Pi 3; 8xRelais; Aptodec Nano V3.0 Pro; FS1000a; RF-5V; Hama TS33C; 3x Brennerstuhl FunkSteckdosen; 9x Dooya funk Rollo; KWL Systemair VR400; Thermokon Modbusthermostat; diverse China Modbus Thermostate; 1-wire Bus; Telegram; QuickFhem; FhemNative; Firmata; Alexa ......

wthiess

##############################################
# $Id: 99_Utils.pm 10570 2016-01-19 06:39:23Z rudolfkoenig $
package main;

use strict;
use warnings;
use POSIX;

sub
Utils_Initialize($$)
{
  my ($hash) = @_;
}

sub
time_str2num($)
{
  my ($str) = @_;
  my @a;
  if($str) {
    @a = split("[T: -]", $str);
    return mktime($a[5],$a[4],$a[3],$a[2],$a[1]-1,$a[0]-1900,0,0,-1);
  } else {
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    return mktime($sec, $min, $hour, $mday, $mon, $year, 0, 0, -1);
  }
}

sub
min($@)
{
  my ($min, @vars) = @_;
  for (@vars) {
    $min = $_ if $_ lt $min;
  }           
  return $min;
}

sub
max($@)
{
  my ($max, @vars) = @_;
  for (@vars) {
    $max = $_ if $_ gt $max;
  }           
  return $max;
}

sub
minNum($@)
{             
  my ($min, @vars) = @_;
  for (@vars) {
    $min = $_ if $_ < $min;
  }           
  return $min;
}

sub
maxNum($@)
{             
  my ($max, @vars) = @_;
  for (@vars) {
    $max = $_ if $_ > $max;
  }           
  return $max;
}


sub
abstime2rel($)
{
  my ($h,$m,$s) = split(":", shift);
  $m = 0 if(!$m);
  $s = 0 if(!$s);
  my $t1 = 3600*$h+60*$m+$s;

  my @now = localtime;
  my $t2 = 3600*$now[2]+60*$now[1]+$now[0];
  my $diff = $t1-$t2;
  $diff += 86400 if($diff <= 0);

  return sprintf("%02d:%02d:%02d", $diff/3600, ($diff/60)%60, $diff%60);
}

sub
defInfo($;$)
{
  my ($search,$internal) = @_;
  $internal = 'DEF' unless defined($internal);
  my @ret;
  my @etDev = devspec2array($search);
  foreach my $d (@etDev) {
    next unless $d;
    push @ret, $defs{$d}{$internal};
  }
  return @ret;
}

my ($SVG_lt, $SVG_ltstr);
sub
SVG_time_to_sec($)
{
  my ($str) = @_;
  if(!$str) {
    return 0;
  }
  my ($y,$m,$d,$h,$mi,$s) = split("[-_:]", $str);
  $s = 0 if(!$s);
  $mi= 0 if(!$mi);
  $h = 0 if(!$h);
  $d = 1 if(!$d);
  $m = 1 if(!$m);

  if(!$SVG_ltstr || $SVG_ltstr ne "$y-$m-$d-$h") { # 2.5x faster
    $SVG_lt = mktime(0,0,$h,$d,$m-1,$y-1900,0,0,-1);
    $SVG_ltstr = "$y-$m-$d-$h";
  }
  return $s+$mi*60+$SVG_lt;
}


######## trim #####################################################
# What  : cuts blankspaces from the beginning and end of a string
# Call  : { trim(" Hello ") }
# Source: http://www.somacon.com/p114.php ,
#         http://www.fhemwiki.de/wiki/TRIM-Funktion-Anfangs/EndLeerzeichen_aus_Strings_entfernen
sub trim($)
{
   my $string = shift;
   $string =~ s/^\s+//;
   $string =~ s/\s+$//;
   return $string;
}

######## ltrim ####################################################
# What  : cuts blankspaces from the beginning of a string
# Call  : { ltrim(" Hello") }
# Source: http://www.somacon.com/p114.php ,
#         http://www.fhemwiki.de/wiki/TRIM-Funktion-Anfangs/EndLeerzeichen_aus_Strings_entfernensub ltrim($)
sub ltrim($)
{
   my $string = shift;
   $string =~ s/^\s+//;
   return $string;
}

######## rtrim ####################################################
# What  : cuts blankspaces from the end of a string
# Call  : { rtrim("Hello ") }
# Source: http://www.somacon.com/p114.php ,
#         http://www.fhemwiki.de/wiki/TRIM-Funktion-Anfangs/EndLeerzeichen_aus_Strings_entfernensub ltrim($)
sub rtrim($)
{
   my $string = shift;
   $string =~ s/\s+$//;
   return $string;
}

######## UntoggleDirect ###########################################
# What  : For devices paired directly, converts state 'toggle' into 'on' or 'off'
# Call  : { UntoggleDirect("myDevice") }
#         define untoggle_myDevice notify myDevice { UntoggleDirect("myDevice") }
# Source: http://www.fhemwiki.de/wiki/FS20_Toggle_Events_auf_On/Off_umsetzen
sub UntoggleDirect($)
{
my ($obj) = shift;
Log 4, "UntoggleDirect($obj)";
if (Value($obj) eq "toggle"){
   if (OldValue($obj) eq "off") {
     {fhem ("setstate ".$obj." on")}
   }
   else {
     {fhem ("setstate ".$obj." off")}
   }
}
else {
   {fhem "setstate ".$obj." ".Value($obj)}

}


######## UntoggleIndirect #########################################
# What  : For devices paired indirectly, switches the target device 'on' or 'off' also when a 'toggle' was sent from the source device
# Call  : { UntoggleIndirect("mySensorDevice","myActorDevice","50%") }
#         define untoggle_mySensorDevice_myActorDevice notify mySensorDevice { UntoggleIndirect("mySensorDevice","myActorDevice","50%%") }
# Source: http://www.fhemwiki.de/wiki/FS20_Toggle_Events_auf_On/Off_umsetzen
sub UntoggleIndirect($$$)
{
  my ($sender, $actor, $dimvalue) = @_;
  Log 4, "UntoggleIndirect($sender, $actor, $dimvalue)";
  if (Value($sender) eq "toggle")
  {
    if (Value($actor) eq "off") {fhem ("set ".$actor." on")}
    else {fhem ("set ".$actor." off")}
  }
  ## workaround for dimming currently not working with indirect pairing
  ## (http://culfw.de/commandref.html: "TODO/Known BUGS - FS20 dim commands should not repeat.")
  elsif (Value($sender) eq "dimup") {fhem ("set ".$actor." dim100%")}
  elsif (Value($sender) eq "dimdown") {fhem ("set ".$actor." ".$dimvalue)}
  elsif (Value($sender) eq "dimupdown")
  {
    if (Value($actor) eq $dimvalue) {fhem ("set ".$actor." dim100%")}
       ## Heuristic above doesn't work if lamp was dimmed, then switched off, then switched on, because state is "on", but the lamp is actually dimmed.
    else {fhem ("set ".$actor." ".$dimvalue)}
    sleep 1;
  }
  ## end of workaround
  else {fhem ("set ".$actor." ".Value($sender))}

  return;
}

sub
IsInt($)
{
  defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
}

# Small NC replacement: fhemNc("ip:port", "text", waitForReturn);
sub
fhemNc($$$)
{
  my ($addr, $txt, $waitForReturn) = @_;
  my $client = IO::Socket::INET->new(PeerAddr => $addr);
  return "Can't connect to $addr\n" if(!$client);
  syswrite($client, $txt);
  return "" if(!$waitForReturn);
  my ($ret, $buf) = ("", "");
  shutdown($client, 1);
  alarm(5);
  while(sysread($client, $buf, 256) > 0) {
    $ret .= $buf;
  }
  alarm(0);
  close($client);
  return $ret;
}


sub
round($$)
{
  my($v,$n) = @_;
  return sprintf("%.${n}f",$v);
}

sub
DebianMail

my $rcpt = shift;
my $subject = shift;
my $text = shift;
my $attach = shift;
my $ret = "";
my $sender = "office@xx.at";
my $konto = "office#xxxxxxxxx.at";
my $passwrd = "xxxxxxxxxxxxx";
my $provider = "smtp.xxxxxxxx.at:25";
Log 1, "sendEmail RCP: $rcpt";
Log 1, "sendEmail Subject: $subject";
Log 1, "sendEmail Text: $text";
Log 1, "sendEmail Anhang: $attach";;

$ret .= qx(sendEmail -f '$sender' -t '$rcpt' -u '$subject' -m '$text' -a '$attach' -s '$provider' -xu '$konto' -xp '$passwrd' -o tls=auto -o message-charset=utf-8);
$ret =~ s,[\r\n]*,,g;    # remove CR from return-string
Log 1, "sendEmail returned: $ret";
}

1;

=pod
=item helper
=begin html

<a name="Utils"></a>
<h3>Utils</h3>
<ul>
  This is a collection of functions that can be used module-independant
  in all your own development<br/>
  </br>
  <b>Defined functions</b><br/><br/>
  <ul>
    <li><b>abstime2rel("HH:MM:SS")</b><br>tells you the difference as HH:MM:SS
      between now and the argument</li><br/>

    <li><b>ltrim("string")</b><br>returns string without leading
      spaces</li><br/>

    <li><b>max(str1, str2, ...)</b><br>returns the highest value from a given
      list (sorted alphanumeric)</li><br/>

    <li><b>maxNum(num1, num2, ...)</b><br>returns the highest value from a
      given list (sorted numeric)</li><br/>

    <li><b>min(str1, str2, ...)</b><br>returns the lowest value from a given
      list (sorted alphanumeric)</li><br/>

    <li><b>minNum(num1, num2, ...)</b><br>returns the lowest value from a given
      list (sorted numeric)</li><br/>

    <li><b>rtrim("string")</b><br>returns string without trailing
      spaces</li><br/>

    <li><b>time_str2num("YYYY-MM-DD HH:MM:SS")</b><br>convert a time string to
      number of seconds since 1970</li><br/>

    <li><b>trim("string")</b><br>returns string without leading and without
      trailing spaces</li><br/>

    <li><b>UntoggleDirect("deviceName")</b><br>For devices paired directly,
       converts state 'toggle' into 'on' or 'off'</li><br/>

    <li><b>UntoggleIndirect()</b><br>For devices paired indirectly, switches
      the target device 'on' or 'off', also when a 'toggle' was sent from the
      source device</li><br/>

    <li><b>defInfo("devspec", "internal")</b><br>return an array with the
      internal values of all devices found with devspec, e.g.
      defInfo("TYPE=SVG", "GPLOTFILE").</li><br/>

    <li><b>SVG_time_to_sec("YYYY-MM-DD_HH:MM:SS")</b><br>converts the argument
      to the number of seconds since 1970. Optimized for repeated use of similar
      timestamps.</li></br>

    <li><b>fhemNc("host:port", "textToSend", waitForReturn)</b><br>
      sends textToSend to host:port, and if waitForReturn is set, then read
      the answer (wait up to 5 seconds) and return it. Intended as small
      nc replacement.
      </li></br>

    <li><b>round(value, digits)</b><br>
      round &lt;value&gt; to given digits behind comma
      </li></br>

    <li><b>getUniqueId()</b><br>
      return the FHEM uniqueID used by the fheminfo command. Uses the
      getKeyValue / setKeyValue functions.
      </li></br>

    <li><b>setKeyValue(keyName, value)</b><br>
      store the value in the file $modpath/FHEM/FhemUtils/uniqueID (the name is
      used for backward compatibility), or in the database, if using configDB.
      value may not contain newlines, and only one value per key is stored.
      The file/database entry will be written immediately, no explicit save is
      required.  If the value is undef, the entry will be deleted.
      Returns an error-string or undef.
      </li></br>

    <li><b>getKeyValue(keyName)</b><br>
      return ($error, $value), stored previously by setKeyValue.
      $error is set if there was an error.  Both are undef, if there is no
      value yet for this key.
      </li></br>

  </ul>
</ul>
=end html
=cut
Raspberry Pi 3; 8xRelais; Aptodec Nano V3.0 Pro; FS1000a; RF-5V; Hama TS33C; 3x Brennerstuhl FunkSteckdosen; 9x Dooya funk Rollo; KWL Systemair VR400; Thermokon Modbusthermostat; diverse China Modbus Thermostate; 1-wire Bus; Telegram; QuickFhem; FhemNative; Firmata; Alexa ......

Otto123

Hallo!
die 99_myUtils ... und nicht die 99_Utils
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

wthiess

ah jetzt kapiert.  my my my
Raspberry Pi 3; 8xRelais; Aptodec Nano V3.0 Pro; FS1000a; RF-5V; Hama TS33C; 3x Brennerstuhl FunkSteckdosen; 9x Dooya funk Rollo; KWL Systemair VR400; Thermokon Modbusthermostat; diverse China Modbus Thermostate; 1-wire Bus; Telegram; QuickFhem; FhemNative; Firmata; Alexa ......

Otto123

Zitat von: wthiess am 22 Juni 2016, 11:11:02
99_myUtils meinete ich eh Entschuldigung. Schreibfehler. so wie im Wicki beschrieben.

Aber laut deinem Post mit der 99_Utils hast Du sie wirklich dort in die 99_Utils und eben nicht in die 99_myUtils rein geschrieben. Also stelle da bitte das original wieder her!
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

wthiess

so nun bin ich in richtigen Datei. Aber noch kein Erfolg
Der Befehl
{ DebianMail('office@telso.at','Test','Test-Text');; }
brinmgt folgende Meldung:
Undefined subroutine &main::DebianMail called at (eval 1159) line 1.

hier ein Auszug aus der Fheml.log
2016.06.22 11:42:31 1: PERL WARNING: Possible unintended interpolation of @affirnet in string at ./FHEM/99_myUtils.pm line 27.
2016.06.22 11:42:31 1: reload: Error:Modul 99_myUtils deactivated:
Global symbol "@affirnet" requires explicit package name at ./FHEM/99_myUtils.pm line 27.


hier die Datei 99_myUtils.pm
##############################################
# $Id: myUtilsTemplate.pm 7570 2015-01-14 18:31:44Z rudolfkoenig $
#
# Save this file as 99_myUtils.pm, and create your own functions in the new
# file. They are then available in every Perl expression.

package main;

use strict;
use warnings;
use POSIX;

sub
myUtils_Initialize($$)
{
  my ($hash) = @_;
}

sub
DebianMail
{
my $rcpt = shift;
my $subject = shift;
my $text = shift;
my $attach = shift;
my $ret = "";
my $sender = "office@affirnet.at";
my $konto = "office#affirnet.at";
my $passwrd = "12345671234567";
my $provider = "smtp.affirnet.at:25";
Log 1, "sendEmail RCP: $rcpt";
Log 1, "sendEmail Subject: $subject";
Log 1, "sendEmail Text: $text";
Log 1, "sendEmail Anhang: $attach";;

$ret .= qx(sendEmail -f '$sender' -t '$rcpt' -u '$subject' -m '$text' -a '$attach' -s '$provider' -xu '$konto' -xp '$passwrd' -o tls=auto -o message-charset=utf-8);
$ret =~ s,[\r\n]*,,g;    # remove CR from return-string
Log 1, "sendEmail returned: $ret";
}

1;
Raspberry Pi 3; 8xRelais; Aptodec Nano V3.0 Pro; FS1000a; RF-5V; Hama TS33C; 3x Brennerstuhl FunkSteckdosen; 9x Dooya funk Rollo; KWL Systemair VR400; Thermokon Modbusthermostat; diverse China Modbus Thermostate; 1-wire Bus; Telegram; QuickFhem; FhemNative; Firmata; Alexa ......

Otto123

#10
hast Du ein reload 99_myUtils.pm gemacht nachdem Du die Änderung rein geschrieben hast?

und hier ist ein Tippfehler
my $konto = "office#affirnet.at";
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

Brice

my $konto = "office#affirnet.at";
korrigier mal das #
FHEM auf RPi 4 4GB (Buster) | produktiv) CUL 868 für FS20 | S300TH | KS300 | Max!Cube als CUN 868 für TechemWZ | HM-MOD-RPI-PCB für HM | Z-Wave ZME_UZB1 | FRITZ!DECT 200 | HUE | Lightify | Echo Dot | WS3080

kumue

muss er nicht zwingend tun  ;)

Aus dem Wiki..

ZitatBei der Bearbeitung über den Integrierten Editor wird die Programmdatei beim Abspeichern automatisch mit den Änderungen neu geladen.

Bei der nicht empfohlenen Bearbeitung der Programmdatei mit einem externen Editor muss Fhem manuell angewiesen werden, die Programmdatei mit den Änderungen zu laden.

Otto123

Zitat von: kumue am 22 Juni 2016, 12:08:06
muss er nicht zwingend tun  ;)

Aus dem Wiki..
Manches geht auch an einem vorbei, ich glaube dass ist noch nicht immer so?  8)
Geschadet hätte es nicht.
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

kumue

Zitat von: Otto123 am 22 Juni 2016, 12:12:38
Manches geht auch an einem vorbei, ich glaube dass ist noch nicht immer so?  8)
Geschadet hätte es nicht.

ich hab mich nur grad schnell daran erinnert, da ich das erst vor paar tagen von betateilchen gelernt hatte...
wußte ich bis dahin auch nicht, daß der int. editor einen reload anschl. macht.