diff --git a/src/test-mail b/src/test-mail new file mode 100755 index 0000000000000000000000000000000000000000..021ccb68e86618cae0e9b73046efbea18f7c2ab7 --- /dev/null +++ b/src/test-mail @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +# Copyright (C) 2017 Tetras Libre <admin@tetras-libre.fr> +# Author: Beniamine, David <David@Beniamine.net> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +use strict; +use warnings; +use threads ('yield', + 'stack_size' => 64*4096, + 'exit' => 'threads_only', + 'stringify'); +use utf8; +use MIME::Lite; + +sub do_sendmail($$$); + +# Send subject, message by email to root +sub do_sendmail($$$){ + my ($subject, $message, $retry) = @_; + + utf8::encode($subject); + utf8::encode($message); + my $msg = MIME::Lite->new( + From => 'tetras-back', + To => 'root', + Subject => "[Tetras-back] $subject", + Type => 'multipart/mixed' + ); + $msg->attr("content-type.charset" => "UTF-8"); + $msg->attach( + Type => 'text/plain; charset=UTF-8', + Data => $message, + ); + eval{ $msg->send() }; + if($@){ + if($retry == 0){ + do_sendmail($subject,$message,1); + } + }else{ + print("Etat envoyé par courriel"); + } +} + +do_sendmail("[Tetras-back] Test", "Ceci est un message de test du système de sauvegardes", 0);