2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

75_MSGMail: Improve error logging to assist problem solving

git-svn-id: https://svn.fhem.de/fhem/trunk@8568 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
gandy92 2015-05-12 10:16:25 +00:00
parent 22a5fad4c9
commit c62d92674a
2 changed files with 31 additions and 16 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- change: MSGMail: Improve error logging to assist problem solving
- feature: 10_pilight_ctrl possibility to ignore all incomming messages, added protocol quigg_gt*
- change: MSG: Replace file and mail related code with delegates
- change: MSGFile: Assimilate file related code from 75_MSG

View File

@ -4,6 +4,7 @@
#
# History:
#
# 2015-05-11: Improve error logging to assist problem solving
# 2015-05-09: Assimilate mail related code from 75_MSG
# 2015-05-06: Tidy up code for restructuring
# 2015-05-05: Remove dependency on Switch
@ -69,11 +70,13 @@ sub MSGMail_Initialize($)
$MSGMail_SSL = 1;
}
}
Log 2,
Log 0,
"$name: SSL is "
. ( ($MSGMail_SSL)
. (
($MSGMail_SSL)
? ("available, provided by Net::SMTP" . (($MSGMail_SMTP < 3.00) ? "::SSL" : ""))
: "not available");
: "not available"
);
}
##############################################
@ -225,7 +228,7 @@ sub MSGMail_Set($@)
my $mess = "";
for ($i = 0 ; $i < ReadingsVal($name, "msgcount", 0) ; $i++)
{
$mess .= $data{ $name }{$i};
$mess .= $data{$name}{$i};
}
my $mailmsg = MIME::Lite->new(
@ -241,24 +244,28 @@ sub MSGMail_Set($@)
my $smtperrmsg = "SMTP Error: ";
#$smtp = Net::SMTP::SSL->new($smtphost, Port => $smtpport)
$smtp = MSGMail_conn($defs{ $name })
or return $smtperrmsg . " Can't connect to host $smtphost";
$smtp = MSGMail_conn($defs{$name})
or return MSGMail_error($name, "Can't connect to host $smtphost",
$smtperrmsg . " Can't connect to host $smtphost");
$smtp->auth($auth[0], $auth[1])
or return $smtperrmsg . " Can't authenticate: " . $smtp->message();
$smtp->mail($from) or return $smtperrmsg . $smtp->message();
$smtp->to($to) or return $smtperrmsg . $smtp->message();
or
return MSGMail_error($name, "Can't authenticate", $smtperrmsg . " Can't authenticate: " . $smtp->message());
$smtp->mail($from)
or return MSGMail_error($name, "Error setting sender '$from'", $smtperrmsg . $smtp->message());
$smtp->to($to) or return MSGMail_error($name, "Error setting receiver '$to'", $smtperrmsg . $smtp->message());
if ($cc ne '')
{
Log 1, "CC = $cc";
$smtp->cc($cc) or return $smtperrmsg . $smtp->message();
Log3 $name, 1, "$name: CC = $cc";
$smtp->cc($cc)
or return MSGMail_error($name, "Error setting carbon-copy $cc", $smtperrmsg . $smtp->message());
}
$smtp->data() or return $smtperrmsg . $smtp->message();
$smtp->data() or return MSGMail_error($name, "Error setting data", $smtperrmsg . $smtp->message());
$smtp->datasend($mailmsg->as_string)
or return $smtperrmsg . $smtp->message();
$smtp->dataend() or return $smtperrmsg . $smtp->message();
$smtp->quit() or return $smtperrmsg . $smtp->message();
or return MSGMail_error($name, "Error sending email", $smtperrmsg . $smtp->message());
$smtp->dataend() or return MSGMail_error($name, "Error ending transaction", $smtperrmsg . $smtp->message());
$smtp->quit() or return MSGMail_error($name, "Error saying good-bye", $smtperrmsg . $smtp->message());
Log 1, "<MSG> send EMail: <$subject>";
Log3 $name, 1, "$name: successfully sent email w/ subject '$subject'";
} ###> END MSGMail
@ -271,6 +278,13 @@ sub MSGMail_Set($@)
return undef;
}
sub MSGMail_error($$$)
{
my ($name, $msg, $error) = @_;
Log3 $name, 0, "$name: $msg: $error";
return $error;
}
##############################################
# Helper Function to connect to mail server
# Returns a smtp connection (see Net:SMTP)