Thread Probleme mit dem Mailversand nach Umstieg auf Perl 5.10 (26 answers)
Opened by Michael at 2010-12-16 12:07

Gast Michael
 2010-12-16 12:07
#143628 #143628
Hallo Leute,

vorneweg: ich bin ein absoluter Anfänger was Perl betrifft. Sorry :-)

Ich habe mir (mit Hilfe von Perl-Seiten) ein Skript gestrickt, welches mir die Ausgabe eines Shellskriptes als HTML-Email versendet und in die Email zwei Bilder einbettet, sowie eine Textdatei anhängt.

Geschrieben und getestet wurde das Skript unter SLES 10 mit Perl 5.8.8 und hat einwandfrei funktioniert.

Nun haben wir die Server auf SLES 11 umgestellt, welches Perl 5.10 mitbringt. Zwar funktioniert der Versand der HTML-Email noch, aber leider werden die Bilder nicht mehr angezeigt und die Textdatei ist ohne Inhalt.

Ein Gefühl sagt mir, dass die Interpretation der MIME-Typen anscheinend nicht funktioniert. Ich hoffe jemand mit mehr Ahnung als ich kann mir weiterhelfen.

Vielen Dank schonmal für eure Mühen.

Anbei der Code:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl

use MIME::Base64 qw(encode_base64);

$mailprog ='/usr/sbin/sendmail';
open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n)";
print MAIL "To: $ARGV[0] <$ARGV[0]\@yxz.de>\n";
print MAIL "From: $ARGV[1] <noreplay\@xyz.de>\n";
print MAIL "Reply-to: muster\@xyz\n";
print MAIL "Subject: $ARGV[2] $ARGV[3] $ARGV[4]\n";
print MAIL "MIME-Version: 1.0\n";

# Trennerspezifikation für Attachements
print MAIL "Content-Type: multipart/mixed;\n";
print MAIL "\tboundary=mail_attachement===============\n";

# Hinweis, wenn kein MIME-Standard unterstützt wird.
print MAIL "This is a multi-part message in MIME format.\n";
print MAIL "\n";
print MAIL "\n";

# Abgrenzung der Email vom Header
print MAIL "--mail_attachement===============\n";


# Trennerspezifikation Plaint Text mit HTML als Alternative
print MAIL "Content-Type: multipart/alternative;\n";
print MAIL "\tboundary=plain_html===============\n";

# Abgrenzung der PLAIN von HTML
#print MAIL "--plain_html===============\n";
#print MAIL "Content-Type: text/plain; charset=us-ascii\n";
#print MAIL "Content-Transfer-Encoding: quoted-printable\n";

#print MAIL "Alternative als Plain Text\n";

# neuer Content-Type sobald sich ein Bild im HTMLTEIL befindet
print MAIL "--plain_html===============\n";
print MAIL "Content-Type: multipart/related;\n";
print MAIL "\tboundary=html_images===============\n";

# Abgrenzung der HTMLQUELLCODE vom Bild
print MAIL "--html_images===============\n";
print MAIL "Content-Type: text/html; charset=us-ascii\n";
#print MAIL "Content-Transfer-Encoding: 7bit\n";
open(FILE, "$ARGV[7]/tmp/body.html");
read (FILE, $htmlfile, 60*57);
print MAIL $htmlfile;
close (FILE);

# Einbinden des Bilds
print MAIL "--html_images===============\n";
print MAIL "Content-Type: image/gif\n";
print MAIL "Content-ID: <image001.gif>\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: inline; filename=\"image001.gif\"\n";
### Kodierung auf base64 Basis
open(FILE, "$ARGV[7]/image001.gif");
while (read(FILE, $buf, 60*57))
{
print MAIL encode_base64($buf);
}
close(FILE);
print MAIL "$ARGV[5]\n";

# Einbinden des Bilds
print MAIL "--html_images===============\n";
print MAIL "Content-Type: image/gif\n";
print MAIL "Content-ID: <image002.de.gif>\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: inline; filename=\"image002.gif\"\n";
### Kodierung auf base64 Basis

open(FILE, "$ARGV[7]/image002.gif");
while (read(FILE, $buf1, 60*57))
{
print MAIL encode_base64($buf1);
}
close(FILE);
print MAIL "\n";

# Abgrenzung der HTMLQUELLCODE vom Bild schließen
print MAIL "--html_images===============--\n";

# Abgrenzung der PLAINTEXT vom HTMLTEIL schließen
print MAIL "--plain_html===============--\n";

# Abgrenzung des TEXTTEIL vom ATTACHMENT
print MAIL "--mail_attachement===============\n";
print MAIL "Content-Type: application/octet-stream; name=\"$ARGV[6]\"\n";
print MAIL "Content-ID: <$ARGV[6]>\n";
print MAIL "Content-Transfer-Encoding: 7bit\n";
print MAIL "Content-Disposition: attachement; filename=\"$ARGV[6]\"\n";
open(FILE, "$ARGV[7]/tmp/$ARGV[6]") or die "Can't open data: '$ARGV[6]'!\n$!";
read(FILE, $buf2, 60*57);
print MAIL $buf2;
close(FILE);
print MAIL "\n";

# Abgrenzung des TEXTTEIL vom ATTACHMENT schließen
print MAIL "--mail_attachement===============--\n";

close (MAIL);


Grüße,
Michael
Last edited: 2010-12-16 12:11:34 +0100 (CET)

View full thread Probleme mit dem Mailversand nach Umstieg auf Perl 5.10