Thread Speicherprobelm beim Versenden von Emails mit großem Anhang über Net::SMTP::SSL über CGI (24 answers)
Opened by b.altmann at 2017-07-17 09:31

b.altmann
 2017-07-17 10:42
#186924 #186924
User since
2017-07-17
12 Artikel
BenutzerIn
[default_avatar]
Hier der wesentliche Teil meines Test-Skripts:

Code (perl): (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
  my $smtp;
  my $errormsg;
  my $boundary = 'frontier-'.$domain;
  
  for (my $i=1;$i<=50;$i++) {
    $errormsg = '';
    $betreff = "Test $i mit großen Anhang";
    IO::Socket::SSL::set_defaults(SSL_verify_mode => 0);
    if(!($smtp = Net::SMTP::SSL->new(Host => 'smtp.strato.de',
                                     Hello => $domain,
                                     Timeout => 10,
                                     Port => 465)))
    {
      $errormsg = "Could not connect to SMTP Server: smtp.strato.de<br>";
    }
    else {
      my $error = $smtp->auth('webmaster@'.$domain,$pw) ;
      if (! $error) { 
        $errormsg = 'Cannot authenticate as user webmaster@'.$domain." and/or bad Password for Email - Error $error - Check System Settings<br>";
      }
    }
    
    if ($errormsg eq '') {
      $smtp->mail($emfrom);
      if (!($smtp->recipient($to))) {
        $errormsg .= "Ungültige Email-Adresse: $to<br>".$smtp->message().'<br>';
      }
      $smtp->data();
      $smtp->datasend("To: $emto\n");
      $smtp->datasend("From: $emfrom\n");
      $smtp->datasend('Subject: '.umlaut($betreff)."\n");
      $smtp->datasend("MIME-Version: 1.0\n");
      $smtp->datasend("Content-type: multipart/mixed; boundary=\"$boundary\"\n");
      $smtp->datasend("\n");
      $smtp->datasend("--$boundary\n");
      $smtp->datasend("Content-type: text/html\n");
      $smtp->datasend("\n");
      $smtp->datasend("$emtext\n");
  
      if (-f $verz.$anhang) {
        my $mimetype = 'application/zip';
        if    (lc($anhang) =~ /\.pdf$/)                {$mimetype = 'application/pdf';}
        elsif (lc($anhang) =~ /\.gif$/)                {$mimetype = 'image/gif';}
        elsif (lc($anhang) =~ /\.htm$|\.html$/)        {$mimetype = 'text/html';}
        elsif (lc($anhang) =~ /\.jpg$|\.jpeg$|\.jpe$/) {$mimetype = 'image/jpeg';}
        elsif (lc($anhang) =~ /\.rtf$/)                {$mimetype = 'application/rtf';}
        elsif (lc($anhang) =~ /\.txt$/)                {$mimetype = 'text/plain';}
        elsif (lc($anhang) =~ /\.xls$/)                {$mimetype = 'text/msexcel';}
        elsif (lc($anhang) =~ /\.csv$/)                {$mimetype = 'text/tab-separated-values';}
        elsif (lc($anhang) =~ /\.tif$|\.tiff$/)        {$mimetype = 'image/tiff';}
        elsif (lc($anhang) =~ /\.png$/)                {$mimetype = 'image/png';}
        elsif (lc($anhang) =~ /\.avi$/)                {$mimetype = 'video/ms-video';}
        elsif (lc($anhang) =~ /\.wav$/)                {$mimetype = 'audio/x-wav';}
        elsif (lc($anhang) =~ /\.zip$/)                {$mimetype = 'application/zip';}
        
        $smtp->datasend("\n--$boundary\n");
        $smtp->datasend("Content-Type: $mimetype; name=\"$anhang\"\n");
        $smtp->datasend("Content-Transfer-Encoding: base64\n");
        $smtp->datasend("Content-Disposition: attachment; filename=\"$anhang\"\n");
        $smtp->datasend("\n");
        open(DAT, "$verz$anhang") || die("Could not open $verz$anhang!");
        binmode(DAT);
        while (read(DAT, my $bindata, 72*57)) {
          my $buf = &encode_base64( $bindata );
          $smtp->datasend($buf);
        }
        close(DAT);
      }
      $smtp->datasend("\n--$boundary--\n");
      $smtp->datasend("\n");
      $smtp->dataend();
      $smtp->quit();
      if ($errormsg eq '' && !$smtp->ok) {
        $errormsg .= $smtp->code()." ".$smtp->message()."<br>";
      }
    }
    print "Email $i gesendet: $errormsg<br>";
  }

Ich habe auch mal das Einlesen des Anhangs aus der Schleife rausgenommen (in einem Array gespeichert) und direkt datasend übergeben, hat aber auch nichts verbessert.

modedit Editiert von GwenDragon: BBCode-Tags
Last edited: 2017-07-17 10:55:26 +0200 (CEST)

View full thread Speicherprobelm beim Versenden von Emails mit großem Anhang über Net::SMTP::SSL über CGI