Hallo!
Vielleicht etwas ungewöhnlich...aber ich hoffe es hat schon mal jemand hinbekommen.
Ich nutze das DebianMail auf meinem Raspberry. (https://wiki.fhem.de/wiki/E-Mail_senden)
Außerdem habe ich mir ein rss erstellt das ich mir gerne per Mail senden möchte. Dafür habe ich folgende Definition im meiner myUtils erstellt:
sub SendStatusMail(){
Log 1, "Erstelle Status";
system("wget -v -O /opt/fhem/log/bericht.jpg http://192.168.1.3:8083/fhem/rss/plotpng.jpg &");
fhem("sleep 30 ; {DebianMail('ich\@jemand.de','FHEM Status','<html><body><p><IMG width=800 height=2500 hspace=0 src=cid:bericht.jpg align=baseline border=0><br></p></body></html>','/opt/fhem/log/bericht.jpg')}");
}
In Outlook wird das ganze auch sehr gut angezeigt. Das Bild ist im Text.
Auf meinem Handy mit K9 Mail funktioniert es leider nicht. Das Bild wird nicht angezeigt, sondern ist nur im Anhang verfügbar.
Wenn ich dieses html in Outlook einfüge und mir schicke, dann werden die Bilder problemlos auch auf dem Handy im Text angezeigt.
So sieht es im Quelltext (in Outlook) dann aus:
</head><body lang=DE link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><img width=800 height=600 id="Grafik_x0020_1" src="cid:image001.jpg@01D3693C.6F706EF0" alt="http://192.168.1.3:8083/fhem/rss/plotpng.jpg"><o:p></o:p></p></div></body></html>
Ich habe nur keine Ahnung, wo die id und die Nummer hinter dem @ stammen könnte...
Hat es schon mal jemand geschafft Bilder im Text einer Mail auch anzeigen zu lassen?
Gruß
Bismosa
Hallo,
irgendwie hilft das Fragen immer. Dann kommt immer spontan eine ganz neue Idee auf:
DebianMail muss erweitert werden. Ich habe einfach eine neue sub erstellt:
sub
DebianMailFile
{
my $rcpt = shift;
my $subject = shift;
my $text = shift;
my $attach = shift;
my $ret = "";
my $sender = "SENDER";
my $konto = "KONTO";
my $passwrd = "PASSWORD";
my $provider = "PROVIDER";
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' -o message-file='$text' -a $attach -s '$provider' -xu '$konto' -xp '$passwrd' -o tls=auto -o message-charset=us-ascii);
$ret =~ s,[\r\n]*,,g; # remove CR from return-string
Log 1, "sendEmail returned: $ret";
}
Somit kann nun auch eine Datei als Text übergeben werden.
Dann habe ich
sub SendStatusMail(){
Log 1, "Erstelle Status";
system("wget -v -O /opt/fhem/log/bericht.jpg http://192.168.1.3:8083/fhem/rss/plotpng.jpg &");
fhem("sleep 30 ; {SendStatusMailGo()}");
}
So macht es den sleep Befehl einfacher. Ich muss nicht mehr mit den Hochkommas rumprobieren...
sub SendStatusMailGo(){
use MIME::Base64;
open (my $image, '/opt/fhem/log/bericht.jpg') or die "$!";
binmode $image;
my $raw_string = do{ local $/ = undef; <$image>; };
my $encoded = encode_base64( $raw_string );
# somewhere earlier in the code I define my filename ...
my $outfile = '/opt/fhem/log/statusmail.txt';
if (-f $outfile) {
unlink $outfile || die "Cannot delete $outfile: $!";
}
# here i 'open' the file, saying i want to write to it with the '>>' symbol
open (FILE, ">> $outfile") || die "problem opening $outfile\n";
# here i print a plain text line to the file
print FILE '<html><head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"></head><img src="data:image/jpg;base64,'.$encoded.'" ></html>';
#Um auch in Outlook das anzuzeigen: (das erste bleibt durchgestrichen!)
print FILE '<html><head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"></head><img src=cid:bericht.jpg></html>';
# i close the file when there's nothing else i want to write to it
close(FILE);
DebianMailFile("ich\@jemand.de","FHEM Status","$outfile","/opt/fhem/log/bericht.jpg");
}
Also:
- Bild in BASE64
- Dieses in eine Datei schreiben mit ein bisschen HTML drumrum
- Zusätzlich HTML für Outlook (das Bild das zusätzlich im Anhang ist per cid:...)
- Senden
Puh. Hat mich den ganzen Tag gekostet. Bin jetzt aber glücklich das es funktioniert!
Gruß
Bismosa